Hi all,
wie have some serious problems to get our JUnit Test running. Here is our setup:
- Java 1.7
- Spring-Data JPA 1.3.0.RELEASE
- EclipseLink 2.4.1 with Load Time Weaving (LTW)
- JUnit 4.11
- H2 Database for tests
- target Servlet container Tomcat 7
We want to use LTW in our JUnit Tests to ensure the tests behave the same in tests and in the target servlet container.
Our POM contains
Code:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar"
</argLine>
<useSystemClassloader>true</useSystemClassloader>
</configuration>
</plugin>
to ensure the LTW for the tests.
Before using LTW in tests we had several helper methods in our testcases to create business models like
Code:
@ContextConfiguration(locations={"classpath:/repositories/brand-repository-test.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("junit")
public class BrandRepositoryTest{
@Autowired
private BrandRepository brandRepository;
....
private Brand createTestBrand(){...}
....
}
With this approach the LTW was broken for all tests. We figured out the problem was something with the JUnit classloader, the model entities were loaded before the EclipseLink weaving process was done and the result are annoying error messages like
Code:
ERROR! java.lang.NoSuchMethodError: ..._persistence_checkFetchedForSet(Ljava/lang/String;)V
We were able to solve that issue creating helper classes for creating our test models and the helper classes are injected by Spring so JUnit does not find the business models in the signature or as return value in the test methods.
This approach works for single tests or for a bunch of tests, but if we try to run all tests in the buildprocess it may fail or may not fail - absolutely not acceptable.
Is there any official approach to use Spring-Data JPA in JUnit tests with LTW? Something which ensures that JUnit waits for the weaving process?
Any help is appreciated,
Christoph