【Junit 报错】Test class should have exactly one public zero-argument constructor和Test class can only have one constructor

简介: 错误1: 1 java.lang.Exception: Test class should have exactly one public zero-argument constructor 2 at org.

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

 

解决:

未解决!!!

相关文章
|
Java 测试技术 Android开发
Junit - 期望异常测试(Expected Test)
Junit - 期望异常测试(Expected Test)
1300 0
|
8月前
|
Java
Junit4.12报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Junit4.12报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决
Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决
102 0
导入了Junit依赖,但@Test注解依然爆红~
导入了Junit依赖,但@Test注解依然爆红~
178 0
|
IDE Java Maven
java: 程序包org.junit不存在,无法通过Test测试
IDEA Error: java: 程序包org.junit不存在,无法通过Test测试
2959 0
java: 程序包org.junit不存在,无法通过Test测试
|
Java Spring
第四篇:SpringBoot如何整合Junit -- @SpringBootTest + @Test
第四篇:SpringBoot如何整合Junit -- @SpringBootTest + @Test
245 0
第四篇:SpringBoot如何整合Junit -- @SpringBootTest + @Test
|
Java 测试技术 数据库
Junit - 优先级测试(FixMethodOrder Test)
Junit - 优先级测试(FixMethodOrder Test)
377 0
Junit - 优先级测试(FixMethodOrder Test)
|
测试技术 Android开发
Junit - 超时测试(Timeout Test)
Junit - 超时测试(Timeout Test)
372 0
Junit - 超时测试(Timeout Test)
|
测试技术 Android开发
Junit - 忽略测试(Ignore Test)
Junit - 忽略测试(Ignore Test)
680 0
Junit - 忽略测试(Ignore Test)
|
测试技术 Android开发
Junit - 套件测试(Suite Test)
Junit - 套件测试(Suite Test)
251 0
Junit - 套件测试(Suite Test)