首页 > 代码库 > 【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)
解决:
测试类必须有一个无参数的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)
解决:
未解决!!!
【Junit 报错】Test class should have exactly one public zero-argument constructor和Test class can only have one constructor
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。