JUnit test failing - complaining of missing data that was just inserted

Posted by Collin Peters on Stack Overflow See other posts from Stack Overflow or by Collin Peters
Published on 2010-05-31T18:54:24Z Indexed on 2010/05/31 19:03 UTC
Read the original article Hit count: 237

Filed under:
|
|
|

I have an extremely odd problem in my JUnit tests that I just can't seem to nail down. I have a multi-module java webapp project with a fairly standard structure (DAO's, service clasess, etc...). Within this project I have a 'core' project which contains some abstracted setup code which inserts a test user along with the necessary items for a user (in this case an 'enterprise', so a user must belong to an enterprise and this is enforced at the database level)

Fairly simple so far... but here is where the strangeness begins

  1. some tests fail to run and throw a database exception where it complains that a user cannot be inserted because an enterprise does not exist. But it just created the enterprise in the preceding line of code! And there was no errors in the insertion of the enterprise.
  2. Stranger yet, if this test class is run by itself everything works fine. It is only when the test is run as part of the project that it fails!
  3. And the exact same abstracted code was run by 10+ tests before the one that fails!
  4. f

I have been banging my head against a wall with this for days and haven't really made any progress. I'm not even sure what information to offer up to help diagnose this.

  • Using JUnit 4.4, Spring 2.5.6, iBatis 2.3.0, Postgresql 8.3
  • Switching to org.springframework.jdbc.datasource.DriverManagerDataSource from org.apache.commons.dbcp.BasicDataSource changed the problem. Using DriverManagerDataSource the tests work for the first time, but now all of a sudden a lot of data isn't rolled back in the database! It leaves everything behind. All with no errors
  • Tests fail when run via Eclipse & Maven

Please ask for any info which may help me solve my problem!

© Stack Overflow or respective owner

Related posts about java

Related posts about spring