0

my problem is that when I run tests individually the test work properly but when I run all the tests several tests start to fail.

It looks to be a problem of the applicationContext I have 3 applicationContext but the applicationContext-test import the 2 before.

Some times I do @applicationContext(applicatonContext1.xml)

and other times @applicationContext(applicationContext-test.xml)

I get different exceptions for different tests:

  • SQLGrammarException: could not execute query.
  • Detached entity exceptions
  • ConstraintViolation exception.

Some tests work properly and some no, but I don't know why. Thanks

Josema
  • 445
  • 2
  • 6
  • 22
  • possible duplicate of [Run all JUnit tests indepentently in Eclipse, reloading Spring context each time](http://stackoverflow.com/questions/24854527/run-all-junit-tests-indepentently-in-eclipse-reloading-spring-context-each-time) – Raedwald Jul 20 '14 at 23:00

1 Answers1

0

PutDirtiesContext on test to allow context to be reloaded each time you run test.

Different @ApplicationContext should work fine. I think you not clean the database in your test (because without @DirtiesContext spring will use same context (and same DB) for same @ApplicationContext).

Michail Nikolaev
  • 3,733
  • 22
  • 18
  • Ok that seems that worked. but now I'm getting other exception in the test generated by roo. IllegalStateException: Entity manager has not been injected. And if I run the test individually this work properly – Josema Mar 21 '13 at 14:57
  • Please provide test class annotation – Michail Nikolaev Mar 21 '13 at 15:31
  • I use @RooIntegrationTest(entity = employee.class). It doesn't fail when I do mvn test, only fail in eclipse – Josema Mar 21 '13 at 18:40
  • I have just used @DirtiesContext in the generated roo tests too and this works!. No errors Thanks very much! – Josema Mar 22 '13 at 13:35