I want to do this web application I am creating in the best possible way. All the unit testing examples I have come across are for contollers only. I understand the views would be quite hard to test and perhaps the model layer would need something like DBUNit. What are your thoughts?
Share
Anything in your application that isn’t tested is most likely to be buggy (or get buggy after some change). On the other hand, you won’t be able to test just everything.
What is usually done is to test more what’s more critical and most likely to contain bugs.
Controllers are likely to contain bugs, once they usually contain some logic, and the bugs aren’t too easy to be caught while just running the program. I believe pretty much anything which is not visual is more likely to contain errors, but is usually easier to test.
UI are usually manually tested even in early stages of development (just running the application and seeing what’s happening is a kind of test), and they are usually hard to test automatically. But if you have a web application, and is worried if it runs well on various browsers and resolutions, I’d suggest some Selenium tests.
But usually, it’s useful to ask a few questions: “How screwed would I be if there’s a bug in this part [criticality]? How likely is this part to contain a bug [risk]? How hard is it to test this part [test development time]? How hard is it to keep tests up-to-date [test maintenance time]?”. The answer to these questions may be a good starting point on deciding what to test or not.