After a junit test case ran, should delete test data related with this test case?
Will keeping the test data help the developers to debug the code?
As a good practice the test case must remove its test data after it is finished so that next test case can run with a known initial db state. The test cases should not depend upon the order of run. This also makes debugging a test case easy since it runs from a known initial state.
Yes unit tests should begin and end with "clean" database, file system, etc. Each test should leave things as it found them.
Apart from anything else this helps with re-runnability - you can keep re-running your tests time after time.
Sometimes however when you're developing and debugging it can be useful to disable data-removal.
There is a real craft to achieving all of this, for example when working with Java, Spring, and databases, you can use Spring's transaction management to simply roll back all your changes with zero effort.
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