I am currently writing the unit tests for a php data access object. Obviously I should stress test the server environment at or above expected traffic levels, but as was answered to this question: Should unit tests cover stress testing? there are some cases where you should stress test the code itself.
My question is this: Should I include stress tests in my Unit Test and why or why not? I’m still fairly new to both unit testing and php, so I need to build up a firmer grasp of what sort of tests are recommended in which situations.
Unit testing and stress testing are very different animals, so “No!” don’t combine the two.
Unit Testing is testing against the smallest blocks of code to ensure that they return the right values. Unit testing should be built and executed as you develop the code, the tests can even be written before you start coding (TDD, or Test Driven Development). They then also serve as regression tests as you refactor the code.
Stress testing should be performed against the server environment, using tools like Apache Bench, and is performed against the final application in a deployed state.