Announcement Announcement Module
Collapse
No announcement yet.
Problem with JUnit and Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with JUnit and Spring

    Hello,

    I got the following class I would like to test:

    Code:
    /**
     * 
     */
    package de.webshop.test;
     
    import static org.hamcrest.CoreMatchers.is;
    import static org.hamcrest.CoreMatchers.notNullValue;
    import static org.junit.Assert.assertThat;
     
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    import org.springframework.test.context.transaction.TransactionConfiguration;
    import org.springframework.transaction.annotation.Transactional;
     
    import de.webshop.kundenverwaltung.pojo.Kunde;
    import de.webshop.kundenverwaltung.repository.KundeNotFoundException;
    import de.webshop.kundenverwaltung.service.IKundenverwaltungService;
     
    /**
     * @author X
     *
     */
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations="/config/test.xml")
    @Transactional
    @TransactionConfiguration(defaultRollback=false)
    public class KundenverwaltungTest {
        
        private static final Logger LOGGER = LoggerFactory.getLogger(KundenverwaltungTest.class);
        private static final boolean DEBUG = LOGGER.isDebugEnabled();
        
        @Autowired 
        private IKundenverwaltungService kv;
        
        private static final Long KUNDE_ID_VORHANDEN = Long.valueOf(1);
        
        @Test
        public void findKundeMitIdVorhanden() throws KundeNotFoundException {
            
            if (DEBUG) LOGGER.debug("BEGINN findKundeMitIdVorhanden");
            
            final Long id = KUNDE_ID_VORHANDEN;
            
            final Kunde kunde = kv.findKundeById(id);
            
            assertThat(kunde, is(notNullValue()));
            assertThat(kunde.getId(), is(id));
            
            if (DEBUG) LOGGER.debug("ENDE findKundeMitIdVorhanden");
            
        }
     
    }
    Information from the log-file:

    2009-09-15 20:23:19,877 INFO org.springframework.test.context.TestContextManage r - @TestExecutionListeners is not present for class [class de.webshop.test.KundenverwaltungTest]: using defaults.
    Stacktrace:

    java.lang.IllegalAccessError: tried to access method org.junit.runners.BlockJUnit4ClassRunner.makeNotif ier(Lorg/junit/runners/model/FrameworkMethod;Lorg/junit/runner/notification/RunNotifierLorg/junit/internal/runners/model/EachTestNotifier; from class org.springframework.test.context.junit4.SpringJUni t4ClassRunner
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRu nner.java:173)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
    at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
    at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
    at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:220)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:179 )
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
    What's the problem ? Thanks for help

  • #2
    Spring M3 and JUnit 4.6 works fine for me now, so there is a problem with Spring M4 and Junit 4.7.

    Comment


    • #3
      Originally posted by [damien] View Post
      Spring M3 and JUnit 4.6 works fine for me now, so there is a problem with Spring M4 and Junit 4.7.
      Exactly!

      Here's a quick summary of which JUnit versions are supported with which Spring versions:
      • Spring 2.5.x: JUnit 4.4
      • Spring 3.0 M1: JUnit 4.5
      • Spring 3.0 M2: JUnit 4.5
      • Spring 3.0 M3: JUnit 4.5
      • Spring 3.0 M4: JUnit 4.6
      • Spring 3.0 RC1: JUnit 4.5, 4.6, 4.7

      For details consult the following JIRA issue: http://jira.springframework.org/browse/SPR-5995

      Regards,

      Sam
      Last edited by Sam Brannen; Sep 16th, 2009, 06:11 AM.

      Comment

      Working...
      X