gpt4 book ai didi

junit4 - JUnit 4 : how do I create a suite of suites?

转载 作者:行者123 更新时间:2023-12-04 17:27:48 28 4
gpt4 key购买 nike

运行下面的 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)

感谢您的回答 !

最佳答案

我终于找到了一种通过运行 junit 4 套件来实现我想要实现的方法,即在多模块项目的所有模块中运行所有测试。为此,请使用 Johannes Link ClassPathSuite tool .

下载 jar,将其安装在您的 maven 存储库中,创建一个 allTests 项目,该项目取决于您的 junit 所在的其他项目,并创建一个 AllTestClass。以下是一些代码和 scn 捕获来说明解决方案:

将 jar 安装到你的 maven repo

enter image description here

创建一个 allTests 项目

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>

在 Eclipse 中添加依赖...

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 运行”。

关于junit4 - JUnit 4 : how do I create a suite of suites?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5423430/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com