TDD is something that seems to be on everybody's lips these days, and I have tried some on my own but I don't think I'm getting the idea. I am getting a grip on how to write a unit test, but I don't understand exactly what my unit tests should test.
I know it's quite a lot of large questions, but I haven't become any wiser from reading articles on the internet, as they all seem to be concerned with how to test, and not with what.
As an example - I have (or, am going to write) a GuestbookController, with methods for viewing, adding, editing and removing posts. What do I need to test? How do I do it?
Unit testing ensures that all code meets quality standards before it's deployed. This ensures a reliable engineering environment where quality is paramount. Over the course of the product development life cycle, unit testing saves time and money, and helps developers write better code, more efficiently.
Unit Testing is typically performed by the developer. In SDLC or V Model, Unit testing is the first level of testing done before integration testing. Unit testing is such a type of testing technique that is usually performed by developers.
This confusion seems to be fairly common. UT is all about code coverage. TDD is concerned with features. They are not the same thing [sorry Joel!]
With UT, you write whatever code you want to, then go back and test every single function (even some of the trivial ones).
With TDD, you select the next feature and write the test for that feature first. Write only the test for that feature, and test coverage is irrelevant. You write the test first to force interface decisions to be made up front. Then you write the code to pass the test (bearing in mind the 'simplest thing that can possibly work'). Then you refactor the code based on what you've learned. Then you go on to the next feature (presumably after check-in and re-running all unit tests).
If desired, develop using TDD then go back and complete coverage with UT tools. If you're creating a class library or other API for developers to use, the more test coverage the better ;-)
If you're just writing an app to do five specific things, TDD alone should be sufficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With