5

以下のjunitを実行すると、例外が発生します。

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)

ご回答有難うございます !

4

4 に答える 4

7

私は最終的に、junit 4スイートのスイートを実行して達成したいことを行う方法を見つけました。つまり、マルチモジュールプロジェクトのすべてのモジュールですべてのテストを実行します。これを行うには、Johannes Link ClassPathSuite ツールを使用します。

jar をダウンロードして Maven リポジトリにインストールし、junit が存在する他のプロジェクトに依存する allTests プロジェクトを作成して、AllTestClass を作成します。ソリューションを説明するためのコードと scn キャプチャを次に示します。

jar を Maven リポジトリにインストールします

ここに画像の説明を入力

allTests プロジェクトを作成する

ここに画像の説明を入力

ポン...

<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>

Eclipse に依存関係を追加する ...

ここに画像の説明を入力

ここにすべてのテストクラスがあります

package com.prosveta.backend.serviceimpl;

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

@RunWith(ClasspathSuite.class)
public class AllBackendTests {
}

「JUnitとして実行」するだけです。

于 2011-04-28T20:19:50.720 に答える
2

この例外は通常、テストがクラスパスにないクラスを使用している場合に発生します。クラスパスが正しく設定されていることを確認してください。

于 2012-11-30T09:20:14.113 に答える
2

日食を使用する場合。プロジェクトのプロパティ(プロジェクトを右クリック)/ Javaビルドパス/プロジェクト/ ....テストプロジェクトを追加して、もう一度実行してください:)

于 2011-04-14T14:18:00.203 に答える