Announcement Announcement Module
Collapse
No announcement yet.
@ContextConfiguration required Transactoins? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ContextConfiguration required Transactoins?

    Hello!

    During to migration from JUnit 3.8 to JUnit 4.4 I changed also definitions of my unit-test to use more annotations.

    I have quite small project - target of this project is to test web-services via CXF. So, this project has sprint-core, context and test in dependencies plus some libraries required for building CXF client.

    This project do not used any database, so, it has no any dataSource bean specified, as well as do not worked with transactions at all. So, it has no spring-tx in dependencies.

    Then I declared by unit-test as:
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations={"classpath:/META-INF/emforge-ws-config-test.xml",
            				"classpath:/META-INF/emforge-ws-test.xml"})
    public class BaseWsUnitTest {
    I've got an error during test exection:
    Code:
    java.lang.NoClassDefFoundError: org/springframework/transaction/TransactionDefinition
    	at java.lang.Class.getDeclaredConstructors0(Native Method)
    	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    	at java.lang.Class.getConstructor0(Class.java:2699)
    	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:61)
    	at org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(TestContextManager.java:171)
    	at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:108)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:107)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:79)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
    	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:26)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:24)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:40)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:30)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    That means if it is required spring-tx. If I will add - it will start to tell me that it cannot find dataSource, "transactionManager" bean and so on and so on.


    So, is this requiremenets of Transactions by simple test runner a feature of Spring-Test - or it is a bug?

    Thank you for any suggestions

  • #2
    Hi akakunin,

    I just made a little test using only spring-core, spring-test, spring-test (all version 2.5.2), and Junit 4.4 and it works fine without transactions.

    Can you review your configurations or post extracts here so we can have a closer look?

    Comment


    • #3
      Stefan, thank you for your answer!

      I found my problem in Spring Jira (http://jira.springframework.org/browse/SPR-4333) and seems it is already fixed in Spring 2.5.2.

      Unfortuantelly I cnanot switch to 2.52. until CXF 2.0.5 will not be released (due to some incompatibility problems). But I found solution for my case - declare Configuration Listeners for my test excluding transactinal one:
      Code:
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(locations={"classpath:/META-INF/emforge-ws-config-test.xml",
              						 "classpath:/META-INF/emforge-ws-test.xml"})
      @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})        						 
      public class BaseWsUnitTest {
      Now it works fine for me.

      Comment


      • #4
        Great!

        I didn't know the version of your Spring project so I made the assumption that your are using a current one.

        Comment

        Working...
        X