I attempt to create an large test class.
I am using Junit, Hibernate and TopLink and H2 database. Before I made use of EJB3Unit (including Hibernate and H2).
My test class has 57 test techniques. Basically run all test at the same time randomized a number of test fails. Basically run each test alone, I recieve no error.
Has anybody a concept what is going on wrong? And just how I'm able to prevent this?
- For every test method I produce a new in memory database having a different title.
- I produce a new entitymanagarfactory and entitymanagar instance.
- I have disabled second level caching.
- I create all table via script (no error happens so database is actually fresh).
- I actually do some db actions and test.
- I obvious session and em.
- I drop all object during my in-memory database
- I shut lower the database
- I close em and emf.
Have I to complete more?
It appears that there's dependency one of the tests. ideally you need to restore the database to the original condition after each test using a tearDown method (in JUnit 4, make use of the @After annotation).
If you are already doing that then your dependency is much more subtle. To discover its cause It is best to start carrying out a binary explore the tests: comment out 1 / 2 of your results. When the random failure continues then comment out 1 / 2 of the rest of the half (and so forth). When the failure vanishes then the issue is within the partner: uncomment and comment the partner. This method will converge quite rapidly.
Dependencies really are a possibility with this random failing.
Some other reason could possibly be the order of elements inside a collection. After i was writing an evaluation and relied around the first element. It wasn't sorted so i wasn't certain the item i had been asking was always exactly the same.