首页 > 代码库 > 【Junit 报错】Test class should have exactly one public zero-argument constructor和Test class can only have one constructor

【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.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 have one constructor