java.lang.Exception 没有可运行的方法 junit
我有一个套件,在其中添加了测试类。 我正在使用 Surefire 来运行我的 JUnit。 我的测试类以 test 结尾,并且方法具有 @test 注释。
如何解决这个问题?
I have a suite, inside which I have added the test class.
I am using surefire to run my JUnits.
My test class ends with test and the methods has @test annotations to it.
How can this problem be resolved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是针对这个不完整问题的各种建议(对于那些不幸被谷歌带到这里寻找这个常见问题答案的人):
如果使用 Junit4.x,只需使用注释(@Test);不要创建测试套件:请参阅此问题
原始问题说正在使用“@Test”注释,这应该可以防止错误。但如果之前发生了其他错误,这种情况仍然可能发生,并且 junit 可以用此消息隐藏原始问题。例如,查看 Spring 配置是否存在问题(未设置 @Required 属性)、模拟对象配置错误等。
以避免其他也可能生成此错误的常见问题(例如运行带有“*Test”后缀的类< em>没有有任何@Test方法),尝试更新到surefire插件2.7(当前@2.8.1)和junit 4.7+(当前@4.8.1)以避免此问题(我正在使用 maven3,顺便说一句;为了安全起见,也许在“mvn test”之前执行“mvn clean” )
远景:至少升级到ant 1.7+(当前1.8+)以避免junit 4 测试套件问题
Here are various suggestions for this incomplete question (for those unfortunate enough to be brought here by google looking for an answer to this common issue):
if using Junit4.x, just use annotations (@Test); don't create a test suite: see this question for details.
original question said "@Test" annotation is being used, which should prevent the error. But it can still happen if there are other errors that happen earlier, and junit can hide the original problem with this message. E.g., see if there are problems with Spring configuration (unset @Required attributes), misconfigured mock objects, etc.
to avoid other frequent issues that also may generate this error (such as running classes suffixed by "*Test" that do not have any @Test methods), try updating to the surefire plugin 2.7 (currently @2.8.1) and junit 4.7+ (currently @4.8.1) to avoid this issue (i'm using maven3, btw; perhaps do a "mvn clean" before "mvn test" to be safe)
long shot: upgrade to at least ant 1.7+ (currently 1.8+) to avoid junit 4 test suite issues
您使用的 JUnit 版本至少为 4.X 才能使用注释吗? (马文?)
You are using the correct version of JUnit at least 4.X to be able to use annotations for that? (Maven?)