복붙노트

[SPRING] Spring WebFlow Project의 서비스 레벨에서 junit 테스트를 실행하려고합니다. $ AssumptionViolatedException 가정

SPRING

Spring WebFlow Project의 서비스 레벨에서 junit 테스트를 실행하려고합니다. $ AssumptionViolatedException 가정

Eclipse 내에서 Spring Web Flow Project에서 junit으로 첫 번째 테스트를 실행하고 mvn test로 콘솔에서 테스트를 실행하려고하지만 동일한 오류가 발생합니다.

java.lang.NoClassDefFoundError : org / junit / $ AssumptionViolatedException을 가정합니다.

여기 내 자바 코드 :

package org.uftwf.memberinquiry.text;

import junit.framework.Assert;

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;
import org.uftwf.memberinquiry.model.MemberInquiryInformation;
import org.uftwf.memberinquiry.model.MemberRequest;
import org.uftwf.memberinquiry.service.MemberInquiryService;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:root-config.xml")
public class TestApp {

    @Autowired
    private MemberInquiryService service;

    @Test
    public void testgetMemeberRequestInformation() {

        MemberRequest inMemberRequest = new MemberRequest();

        MemberInquiryInformation testInfo = service.getMemeberRequestInformation(inMemberRequest);

        inMemberRequest.setRequestor("cpilling04@aol.com.dev");


        Assert.assertEquals(testInfo.getFirst_Name(), "Christine");
        Assert.assertEquals(testInfo.getLast_Name(), "Pillings");
    }

}

여기에 내 pom.xml이있다.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.uftwf.memberinquiry</groupId>
    <artifactId>MemberInquiry</artifactId>
    <name>Member Inquiry</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>

    <developers>
        <developer>
            <id>jsmith</id>
            <name>Johnathan Smith</name>
            <email>johnatham.smith@uftwf.org</email>
            <roles>
                <role>Architect</role>
            </roles>
            <organization>uftwf.org</organization>
            <timezone>-5</timezone>
        </developer>
    </developers>

    <properties>
        <java-version>1.5</java-version>
        <springframework-version>3.1.2.RELEASE</springframework-version>
        <springwebflow-version>2.3.1.BUILD-SNAPSHOT</springwebflow-version>
        <springsecurity-version>3.1.2.RELEASE</springsecurity-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
        <hibernate.version>4.1.1.Final</hibernate.version>
    </properties>

    <dependencies>
        <!-- Spring -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework-version}</version>
            <!-- will come with all needed Spring dependencies such as spring-core 
                and spring-beans -->
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${springframework-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework-version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-faces</artifactId>
            <version>${springwebflow-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-cas</artifactId>
            <version>${springsecurity-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-cas-client</artifactId>
            <version>3.0.7.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>cas-client-core</artifactId>
                    <groupId>org.jasig.cas</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.5</version>
        </dependency>




        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.6.2</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Logging -->


        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-ext</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>

        </dependency>
        <!-- JSF-303 Dependency Injection -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- Sun Mojarra JSF 2 runtime -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.7</version>
        </dependency>


        <!-- JSR 303 validation -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>

        <!-- ********************************************************************** 
            ** HIBERNATE DEPENDENCIES ** ********************************************************************** -->

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.0.2.GA</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.0.2.GA</version>
        </dependency>
        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <!-- For testing against latest Spring snapshots -->
        <repository>
            <id>org.springframework.maven.snapshot</id>
            <name>Spring Maven Snapshot Repository</name>
            <url>http://maven.springframework.org/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <!-- For developing against latest Spring milestones -->
        <repository>
            <id>org.springframework.maven.milestone</id>
            <name>Spring Maven Milestone Repository</name>
            <url>http://maven.springframework.org/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- For Hibernate Validator -->
        <repository>
            <id>org.jboss.repository.releases</id>
            <name>JBoss Maven Release Repository</name>
            <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- For Sun Mojarra JSF 2 implementation -->
        <repository>
            <id>maven2-repository.dev.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- For PrimeFaces JSF component library -->

    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <mode>both</mode>
                </configuration>
            </plugin>
        </plugins>

        <finalName>MemberInquiry</finalName>
    </build>
</project>

가장 좋은 부분은 내 오류입니다.

java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
    at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:281)
    at org.springframework.test.context.junit4.SpringMethodRoadie$2.run(SpringMethodRoadie.java:207)
    at org.springframework.test.context.junit4.SpringMethodRoadie.runBeforesThenTestThenAfters(SpringMethodRoadie.java:254)
    at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:234)
    at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:204)
    at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:146)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:151)
    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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.junit.Assume$AssumptionViolatedException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    ... 18 more

해결법

  1. ==============================

    1.어둠 속에서 찍은 사진입니다.하지만 저는 이것을 봄의 포럼에서 발견했습니다. 그것은 여러분의 설정과 일치합니다. 여러분은 Spring 테스트 v2.5와 Junit 4.7을 사용하고 있습니다. 스프링 테스트 v2.5는 Junit v4.4 만 지원할 수 있습니다.

    어둠 속에서 찍은 사진입니다.하지만 저는 이것을 봄의 포럼에서 발견했습니다. 그것은 여러분의 설정과 일치합니다. 여러분은 Spring 테스트 v2.5와 Junit 4.7을 사용하고 있습니다. 스프링 테스트 v2.5는 Junit v4.4 만 지원할 수 있습니다.

    JUnit 4.4로 다운 그레이드하거나 스프링 테스트 v2.5.6으로 업그레이드하여 문제가 없어지는지 확인하십시오.

  2. ==============================

    2.스프링 v2.5를 유지해야하며, JUnit 4.4로 다운 그레이드하면 문제가 해결됩니다.

    스프링 v2.5를 유지해야하며, JUnit 4.4로 다운 그레이드하면 문제가 해결됩니다.

    더욱이 Assume $ AssumptionViolatedException에 숨겨진 원래 원인을 볼 수 있습니다.

    참고로 최신 스프링 테스트 2.5.6으로 이동해도 아무런 변화가 없습니다.

    연결된 SO : Junit4 + Spring 2.5 : Asserts throw "NoClassDefFoundError"

  3. ==============================

    3.스프링 테스트와 junit의 최신 버전을 모두 최신 버전으로 업그레이드해야하고 모든 것이 잘 작동합니다!

    스프링 테스트와 junit의 최신 버전을 모두 최신 버전으로 업그레이드해야하고 모든 것이 잘 작동합니다!

  4. ==============================

    4.스프링 테스트 2.5.x에서 org.junit.Assume에 AssumptionViolatedException이 포함될 것으로 예상했지만 junit 4.10에서는 org.junit.internal 패키지로 이동되었습니다. 테스트는 ClassNotFoundException을 사용하여 실행을 중단합니다 (실패하지 않음).

    스프링 테스트 2.5.x에서 org.junit.Assume에 AssumptionViolatedException이 포함될 것으로 예상했지만 junit 4.10에서는 org.junit.internal 패키지로 이동되었습니다. 테스트는 ClassNotFoundException을 사용하여 실행을 중단합니다 (실패하지 않음).

    내 해결 방법은 4.10을 기반으로하는 JUnit 가정 복사를 추가하고 AssumptionViolatedException (내부에서)을 추가하는 것입니다. 이 로컬 사본은 클래스 경로에 추가해야합니다. IDE 및 빌드 도구가 먼저 있어야합니다.

    public class Assume {
    
        /*
         * Ported this from JUnit 4.4 to satisfy spring-test
         */
        public static class AssumptionViolatedException extends org.junit.internal.AssumptionViolatedException {
            private static final long serialVersionUID = 1L;
    
            public AssumptionViolatedException(Object value, Matcher<?> matcher) {
                super(value, matcher);
            }
        }
        // rest of Assume from JUint 4.10 ....
    }
    

    단점은이 클래스가 분명히 오래되어서 사라질 것이고 코드의 미래 사용자는 그것이 존재한다는 것을 모를 수도 있다는 것이다. 그것은 미래의 실패를 기다리고 있습니다.

    또한 처음로드되지 않을 수도 있습니다. 이 문제를 완화하기 위해 Assume이 먼저로드되었는지 확인하고 테스트하지 않으면 경고합니다.

    import java.net.URL;
    
    public class JUnitSpringTestAssumeOverrideCompatibilityChecker {
        public static void checkAssumeOverridden() {
            URL url = Thread.currentThread().getContextClassLoader().getResource("org/junit/Assume.class");
    
            if (!"file".equals(url.getProtocol())) {
                throw new RuntimeException("Expect local override (1st on classpath) of JUnit 4.10 Assume for spring-test 2.5 compatibility");
            }
        }
    }
    
  5. from https://stackoverflow.com/questions/12497857/trying-to-run-junit-test-on-service-level-of-spring-webflow-project-assumeassu by cc-by-sa and MIT license