Junit 报错Test class should have exactly one public zero-argument constructor和Test class can only ha(代

Posted Angel挤一挤

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Junit 报错Test class should have exactly one public zero-argument constructor和Test class can only ha(代相关的知识,希望对你有一定的参考价值。

错误1:

 1 java.lang.Exception: Test class should have exactly one public zero-argument constructor
 2     at org.junit.runners.BlockJUnit4ClassRunner.validateZeroArgConstructor(BlockJUnit4ClassRunner.java:171)
 3     at org.junit.runners.BlockJUnit4ClassRunner.validateConstructor(BlockJUnit4ClassRunner.java:148)
 4     at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:127)
 5     at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
 6     at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
 7     at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
 8     at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
 9     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
10     at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
11     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
12     at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
13     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
14     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
15     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
16     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
17     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
18     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
19     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
View Code


解决:
测试类必须有一个无参数的public构造函数

 

错误2:

 1 java.lang.IllegalArgumentException: Test class can only have one constructor
 2     at org.junit.runners.model.TestClass.<init>(TestClass.java:48)
 3     at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
 4     at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
 5     at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
 6     at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
 7     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
 8     at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
 9     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
10     at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
11     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
12     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
13     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
14     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
15     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
16     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
17     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
View Code

 

解决:

未解决!!!

以上是关于Junit 报错Test class should have exactly one public zero-argument constructor和Test class can only ha(代的主要内容,如果未能解决你的问题,请参考以下文章

junit单元测试成功,但是报错org.junit.runners.model.InvalidTestClassError: Invalid test class

C++编译报错:error: ‘>>’ should be ‘> >’ within a nested template argument list

C++编译报错:error: ‘>>’ should be ‘> >’ within a nested template argument list

AndroidJUnit4.class 已弃用:如何使用 androidx.test.ext.junit.runners.AndroidJUnit4?

使用Junit单元测试报错“No tests found matching Method test01(Test01) from ClassRequest@5387f9e0“

Junit调试错误,在MyEclipse中执行Junit就报错了