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?

  1. For every test method I produce a new in memory database having a different title.
  2. I produce a new entitymanagarfactory and entitymanagar instance.
  3. I have disabled second level caching.
  4. I create all table via script (no error happens so database is actually fresh).
  5. I actually do some db actions and test.
  6. I obvious session and em.
  7. I drop all object during my in-memory database
  8. I shut lower the database
  9. I close em and emf.

Have I to complete more?

Thanks...

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.

Good hunting.

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.