Isolation
- The first is unit testing, which is away to specify and verify the behavior of individual classes (or other small units of code) in isolation from the rest of the application.
Working together
- The second type is integration testing, which is a way to specify and verify the behavior of multiple components working together, up to and including the entire Web application.
Understanding Unit Testing
unit testing helps me structure my thoughts about how to best implement what I need.
I find that just thinking about what I test helps throw up ideas about potential problems–and that’s before I start dealing with actual bugs and defects.
Using TDD and the Red-Green-Refactor Workflow
test-driven development (TDD) you use unit tests to help design your code.
This can be an odd concept if you are used to
testing after you have finished coding, but there is a lot of sense in this approach. The key concept is a development workflow
called red-green-refactor. It works like this:
- Determine that you need to add a new feature or method to your application.
- Write the test that will validate the behavior of the new feature when it is written.
- Run the test and get a red light
- Write the code that implements the new feature.
- Run the test again and correct the code until you get a green light.
- Refactor the code if required. For example, reorganize the statements, rename the variables, and so on.
- Run the test to confirm that your changes have not changed the behavior of your additions.