Reputation: 89
I'm writing tests for a method in my model. Of course it sounds like I need unit tests, however one of this method's arguments takes the parameters from a form in the rails app. Should I create unit tests or functional tests (or both)?
For the unit tests, I'm just setting a param variable to a hash similar to the output from the form response, however I'm wondering if that's the best approach since the form params could be updated or changed sometime in the future.
Thanks.
Upvotes: 0
Views: 47
Reputation: 7012
You should at minimum have one or more unit tests for your method. Generally you need to cover three things:
If you cover those cases and you aren't doing anything special with passing the parameters to the method, then the functional test becomes less important.
However I still encourage you to do some behavioural testing. Rails is one environment where both unit testing and behavioural/integration testing are easy to accomplish due to the great gems available - mainly RSpec, Cucumber and Capybara. If you write a Cucumber feature then Capybara will pick up the form parameter changes and your feature will fail if anything is amiss.
Upvotes: 2