2011-03-24 6 views
4

아래의 junit을 실행하면 예외가 발생합니다.JUnit 4 : 스위트 룸을 만드는 방법은 무엇입니까?

import org.junit.runner.RunWith; 
import org.junit.runners.Suite; 
import org.junit.runners.Suite.SuiteClasses; 

import com.prosveta.backend.daoimpl.AllDaoImplTests; 

/** 
* Short desc. 
* 
* Longer desc. 
* 
* @author Jean-Pierre Schnyder 
* 
*/ 
@RunWith(Suite.class) 
@SuiteClasses({AllDaoImplTests.class,AllServiceImplTests.class}) 
public class AllBackendTests { 
} 

스택 추적

java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653) 
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460) 
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52) 
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070) 
    at java.lang.Class.getAnnotations(Class.java:3050) 
    at org.junit.runner.Description.createSuiteDescription(Description.java:72) 
    at org.junit.internal.runners.ErrorReportingRunner.getDescription(ErrorReportingRunner.java:25) 
    at org.junit.runner.Runner.testCount(Runner.java:38) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.countTestCases(JUnit4TestClassReference.java:30) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.countTests(RemoteTestRunner.java:487) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:455) 
    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) 
답변에 대한

감사합니다!

답변

2

eclipse를 사용하는 경우; 프로젝트의 속성 (프로젝트를 마우스 오른쪽 버튼으로 클릭)/Java Build Path/Project/.... 테스트 프로젝트를 추가하고 다시 실행하십시오.

6

마침내 내가 실행하고 싶었던 일을 발견했습니다. junit 4 스위트 세트, 즉 멀티 모듈 프로젝트의 모든 모듈에서 모든 테스트 실행. 이를 수행하려면 Johannes Link ClassPathSuite tool을 사용하십시오.

jar 파일을 다운로드하여 메이븐 저장소에 설치하고, junits가있는 다른 프로젝트에 따라 allTestClass를 만드는 allTests 프로젝트를 만듭니다. 여기에 몇 가지 코드와 SCN 캡처 솔루션 설명하기 위해 다음과 같습니다

enter image description here

이 프로젝트 ALLTESTS를 작성하여 받는다는의 repo에 항아리를 설치를

enter image description here

커피 ...

<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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.prosveta.backend</groupId> 
<artifactId>alltests</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<dependencies> 
    <dependency> 
     <groupId>com.prosveta.backend</groupId> 
     <artifactId>serviceimpl</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.prosveta.backend</groupId> 
     <artifactId>daoimpl</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.prosveta.backend</groupId> 
     <artifactId>model</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.junit.extensions</groupId> 
     <artifactId>cpsuite</artifactId> 
     <version>1.2.5</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 
</dependencies> 

은 ... 이클립스 여기에

enter image description here

과 종속성을 추가 모든 테스트 클래스

package com.prosveta.backend.serviceimpl; 

import org.junit.extensions.cpsuite.ClasspathSuite; 
import org.junit.runner.RunWith; 

@RunWith(ClasspathSuite.class) 
public class AllBackendTests { 
} 
입니다그냥 "JUnit으로 실행".

+0

+1 좋은 답변입니다. 그건 그렇고, 나는 당신이 당신의 질문에 그것을 묘사하는 것과 똑같이 일하고 있습니다. 그 프로젝트는 ANT를 사용하고 있었고 원하는 스위트 (대부분의 시간은 AllTestsSuite)가 jUnit ANT 태스크에 매개 변수로 주어졌습니다. 올바르게 기억한다면. – kaskelotti

2

이 예외는 일반적으로 테스트에서 클래스 경로에없는 클래스를 사용할 때 발생합니다. 클래스 경로가 올바르게 설정되었는지 확인하십시오.

+0

어쨌든, 그 예외는 오라클 에러 메시지만큼 유용합니다! :) – nsandersen

관련 문제