【Junit 报错】Test class should have exactly one public zero-argument constructor和Test class can only have one constructor-阿里云开发者社区

开发者社区> angel挤一挤> 正文

【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

 

解决:

未解决!!!

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
mysql修改密码后报错:ERROR 1045:Access denied for user:&#39;root@localhost&#39;(using password:YES)
  重装了mysql,修改了密码,却发现无法连接,报错:Access denied for user 'root'@'localhost' (using password:YES)       查找资料后,大概是说没有给root设置权限,修复方法如下:      1、停止mysql服务,最简单办法:打开任务管理器--服务,关闭MySql。      2、建立一个txt文件mysql-
1504 0
npm run dev 报错!SyntaxError: Use of const in strict mode.
D:initUser20190315renren-fast-vue-masternode_moduleswebpack-dev-serveebpack-dev-server.js:8const fs = require('fs');^^^^^SyntaxError: Use of const in strict mode.
3178 0
【JUnit 报错】java.lang.IncompatibleClassChangeError
使用Junit 测试spring时候报错: 1 java.lang.IncompatibleClassChangeError: class org.springframework.core.LocalVariableTableParameterNameDiscoverer$ParameterNameDiscoveringVisitor has interface org.
930 0
mysql连接数太小,导致网站报错mysql:Too many connections
mysql连接数太小,导致网站报错mysql:Too many connections
1658 0
【hibernate 报错】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 【get和load的区别】
报错: 1 HTTP Status 500 - Could not write content: No serializer found for class org.hibernate.proxy.
1034 0
git拉取分支报错:fatal:‘XXX' is not a commit and a branch ‘XXX' cannot be created from it
本文首发于公众号“AntDream”,欢迎微信搜索“AntDream”或扫描文章底部二维码关注,和我一起每天进步一点点 问题出现的步骤 首先通过SourceTree新建一个新的分支,新建分支的时候是基于远程分支的某次提交 然后将新建的分支推送到远程 最后在本地git目录文件夹中,通过...
4935 0
Hibernate中HQL语句查询指定字段值报错:ClassCastException: [java.lang.Object; cannot be cast to bean.PersonStatic
在有一次通过如下HQL语句进行查找相应字段时: String hql = "select sum(search),sum(geometry),sum(greedy), sum(graph),sum(number),sum(simulate),sum(combine),sum(structure) from PersonStatis ps where ps.
943 0
+关注
angel挤一挤
【任何0基础都能看懂的步骤和解决方法!】
340
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载