2 ms·
Unit tests don't take that long. If it takes you that much longer to write your unit tests, you must be doing something fundamentally wrong - like perhaps testi
by swombat 18y ago
Unit tests don't take that long. If it takes you that much longer to write your unit tests, you must be doing something fundamentally wrong - like perhaps testing the wrong thing or focusing on the wrong kind of testing.
- Daniel_Newby 18y agoIt is hard to make inline unit tests when the inputs and outputs are really complicated, like the request/reply data structures in a web framework.
- swombat 18y agoTotally agree, that's why you need good MVC separation and you test those layers separately. The models testing is obvious. What you're referring to there is controller testing. In Rails/Rspec, the way you do that is by mocking/stubbing the models (so you're only testing the controller logic). Then you pass in the parameters that would come in from the web, and check that the controller code (which should be fairly straightforward) behaves appropriately. This article explains this approach quite clearly: http://www.patmaddox.com/blog/2007/9/15/easy-controller-tests-and-expressing-intent-through-expectations http://www.patmaddox.com/blog/2007/9/15/easy-controller-test...