JUnit 4:如何创建一套套件?
运行下面的 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)
感谢您的回答!
Running the junit below raises an exception.
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 {
}
Stack trace
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)
Thanks for your answer !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果你使用eclipse;项目属性(右键单击项目)/ Java 构建路径/项目/ ....添加您的测试项目..然后再次运行:)
If you use eclipse; Properties of Project (Right click on project) / Java Build Path / Project / ....Add your testing projects..and run again :)
当测试使用不在类路径中的类时,通常会引发此异常。只需确保您的类路径设置正确即可。
This exception is usually raised when the test is using a class that is not in the classpath. Just make sure your classpath is correctly set.
当我尝试使用 spring 框架执行一些测试时,我遇到了同样的问题。
如果您正在开发 Maven 项目,请尝试添加此依赖项:
这是我的整个 pom.xml
此配置对我来说工作正常。
I had the same problem when I was trying to execute some tests using spring framework.
If you are working on a Maven project, try to add this dependency:
This is my entire pom.xml
This configuration is working properly for me.
我终于找到了一种通过运行 junit 4 套件来实现我想要实现的目标的方法,即在多模块项目的所有模块中运行所有测试。为此,请使用 Johannes Link ClassPathSuite 工具。
下载 jar,将其安装在您的 Maven 存储库中,创建一个 allTests 项目,该项目取决于您的 junit 所在的其他项目,并创建一个 AllTestClass。以下是一些代码和 scn 捕获来说明解决方案:
将 jar 安装到您的 Maven 存储库中
创建一个 allTests 项目
pom .. .
在 Eclipse 中添加依赖项...
这是全部测试类,
您只需“作为 JUnit 运行”。
I finally found a way of doing what I wanted to achieve with running a junit 4 suite of suites, i.e. running all the tests in all the modules of a multimodule project. To do that, use the Johannes Link ClassPathSuite tool.
Download the jar, install it in your maven repo, create a allTests project which depends on your other projects where your junits reside and create an AllTestClass. Here are some code and scn capture to illustrate the solution:
Install the jar into your maven repo
Create an allTests project
the pom ...
Add dependencies in Eclipse ...
and here is the all tests class
which you just "run as JUnit".