1. Make sure to write each tests completely independent of other.
2. Don't depend on the order of execution of the tests and it is not guarenteed.
3. Use mocks for external classes and test logic for only one class at a time.
4. And always verify the mocks to validate execution behavior with expected results.
5. Divide the steps in a test into setup, test, verify sections so that its easy to read.
when using spring-context.xml for spring applications.
@DirtiesContext is useful when it is necessary to re-initialize the auto-wiring of beans so that we make use of fresh copies of beans on each test.
This annotation will make sure that after the test, the new objects are created and injected.