eclipse java.lang.exception 没有可运行的方法 junit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2818570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:44:02  来源:igfitidea点击:

java.lang.exception no runnable methods junit

eclipsejunit

提问by saurav

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.

我有一个套件,在其中添加了测试类。我正在使用 surefire 来运行我的 JUnit。我的测试类以 test 结束,方法有 @test 注释。

How can this problem be resolved?

如何解决这个问题?

回答by michael

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 questionfor 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 nothave 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

  • 如果使用 Junit4.x,只需使用注释(@Test);不要创建测试套件:有关详细信息,请参阅此问题

  • 原始问题说正在使用“@Test”注释,这应该可以防止错误。但是如果之前发生了其他错误,它仍然可能发生,并且junit可以通过此消息隐藏原始问题。例如,查看 Spring 配置是否存在问题(未设置 @Required 属性)、错误配置的模拟对象等。

  • 为避免也可能产生此错误的其他常见问题(例如运行没有任何 @Test 方法的以“*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测试套件问题

回答by khmarbaise

You are using the correct version of JUnit at least 4.X to be able to use annotations for that? (Maven?)

您正在使用至少 4.X 的正确版本的 JUnit 以便能够为此使用注释?(马文?)