Results 1 to 6 of 6

Thread: @RunWith(SpringJUnit4ClassRunner.class) NoSuchMethodError

  1. #1
    Join Date
    May 2007
    Location
    Rome
    Posts
    67

    Default @RunWith(SpringJUnit4ClassRunner.class) NoSuchMethodError

    Running my Spring unit test on Continuum give errors. Any idea how to solve this?

    Running the same test in eclipse or on the prompt runs without problems.



    The code
    Code:
    package org.fao.fishstat.sdmx.formaliser;
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public class FormalisationProcesTest {
    
    	FormalisationProces formalisationProces;
    
    	@Test
    	public void testExecuteProcess() {
    		formalisationProces.executeProcess();
    	}
    
    	@Autowired
    	public void setFormalisationProces(FormalisationProces formalisationProces) {
    		this.formalisationProces = formalisationProces;
    	}
    
    }
    The error:
    Code:
    Running org.fao.fishstat.sdmx.formaliser.FormalisationProcesTest
    org.apache.maven.surefire.booter.SurefireExecutionException: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V; nested exception is java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
    java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:155)
    	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
    	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
    	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
    	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

  2. #2
    Join Date
    May 2007
    Location
    Rome
    Posts
    67

    Default

    Using Junit 4.4 instead of 4.7 did not make any difference, the surefire component kept failing anyway...
    Upgrading Maven to 2.2.1 did not work either.

    But I have found a workaround:
    Instead of using
    @ContextConfiguration
    I am using now
    @ContextConfiguration("/applicationContext-text.xml")

    Now it is running fine on Continuum with Junit 4.7.

  3. #3

    Default Getting exception while testing spring application

    ava.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAbor ted(Lorg/junit/runner/Description;Ljava/lang/ThrowableV




    import static org.junit.Assert.assertTrue;

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.test.context.ContextConfigurat ion;
    import org.springframework.test.context.junit4.SpringJUni t4ClassRunner;

    import com.sysponent.form.Contact;
    import com.sysponent.service.ContactService;


    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations={"/test.xml"})
    public class TestController {




    private ContactService contactService;



    @Test
    public void testInsertion() throws Exception {


    Contact contact=new Contact();

    contact.setFirstname("test");
    contact.setLastname("case");
    contact.setEmail("sristi.lohani@gmail.com");
    contact.setTelephone("9437105841");
    contactService.addContact(contact);
    assertTrue(true);

    }

    }





    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...spring-aop.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ng-context.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schem...spring-jee.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schem...pring-lang.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schem...pring-util.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">


    <context:annotation-config />
    <context:component-scan base-package="com.sysponent" />


    <bean id="messageSource"
    class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
    <property name="basename" value="classpath:messages" />
    <property name="defaultEncoding" value="UTF-8" />
    </bean>


    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer"
    p:location="com/sysponent/assertion/jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close" p:driverClassName="com.mysql.jdbc.Driver"
    p:url="jdbc:mysql://localhost:3306/test" p:username="sa" password=" " />


    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
    <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property name="configurationClass">
    <value>org.hibernate.cfg.AnnotationConfiguration </value>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.show_sql">true</prop>

    <prop key="current_session_context_class">thread</prop>
    </props>
    </property>
    </bean>

    <tx:annotation-driven />

    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean
    class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping" />
    <bean
    class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter" />



    <bean class="com.sysponent.assertion.TestController" />



    </beans>





    Thanks in advance

  4. #4
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    286

    Default

    @sristi.lohani1, what is the problem you are having?

    And please use tags when you post code
    Amila Domingo

  5. #5

    Default

    Thanks for replying amila

    When I am using @RunWith(SpringJUnit4ClassRunner.class) annotation while testing it gives me an exception of
    java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAbor ted(Lorg/junit/runner/Description;Ljava/lang/ThrowableV

    I have tried all the versions of Junit jar but then also the problem exists.

    Thanks in advance

  6. #6
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    286

    Default

    Can you post one of the tests that fails with the configurations you used.
    Amila Domingo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •