并非所有的 junit 测试都在 eclipse 中运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16517292/
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 20:29:03  来源:igfitidea点击:

not all junit tests are running in eclipse

javaeclipsejunit

提问by oshai

I have a java project in eclipse, when I press the project right click -> run as junitsome tests do not run. I attached a picture, see YamiMailSenderTestfor example.
When I try to run the tests directly they are running.
I am using eclipse 3.7.2.

我在 eclipse 中有一个 java 项目,当我按下project right click -> run as junit一些测试时没有运行。我附上了一张图片,YamiMailSenderTest例如参见。
当我尝试直接运行测试时,它们正在运行。
我正在使用 Eclipse 3.7.2。

enter image description here

在此处输入图片说明

and expanded view:

和扩展视图:

enter image description here

在此处输入图片说明

Any idea?

任何的想法?

回答by MTen

Ran into the same problem, my error was that I wrote: public void myMethodName(){ //assertions }

遇到同样的问题,我的错误是我写道: public void myMethodName(){ //assertions }

instead of: public void testMyMethodName() { //assertions }

代替: public void testMyMethodName() { //assertions }

the test before the MyMethodName is important.

MyMethodName 之前的测试很重要。

回答by Gondlar

It's a bit late, but in case anyone finds this via a search engine:

有点晚了,但万一有人通过搜索引擎找到了这个:

If a Test is run multiple times the results provided by JUnit are indistinguishable for those Tests and thus the results are only displayed for one run. See also the following Eclipse bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=172256

如果一个测试多次运行,JUnit 提供的结果对于这些测试是无法区分的,因此结果只显示一次运行。另请参阅以下 Eclipse 错误报告:https: //bugs.eclipse.org/bugs/show_bug.cgi?id=172256

回答by CloudyMarble

Check if you are excluding testsfrom run by attributes and check under Run > Run Configurationsif your JUnit configuration are excluding any tests.

检查您是否从属性运行中排除测试,并检查Run > Run Configurations您的 JUnit 配置是否排除任何测试。

回答by Mawia

In jUnit 4, a test case needs to have @Testannotation. The test case can be set to ignore with @Ignoreannotation. The whole test class can also be set to ignore by placing the @Ignoreannotation right above the class declaration. Note: In jUnit 4 , there is no need to extend Testcase class as in jUnit 3. Everything is in annotation.

在 中jUnit 4,一个测试用例需要有@Test注解。可以使用@Ignore注释将测试用例设置为忽略。通过在类声明的正上方放置@Ignore注释,也可以将整个测试类设置为忽略。注意:在 jUnit 4 中,不需要像在 jUnit 3 中那样扩展 Testcase 类。一切都在注解中。

I have no idea about jUnit 3 since I use only 4.

我不知道 jUnit 3,因为我只使用 4。

回答by CKuharski

I had a similar problem. For some reason, the "Run As -> jUnit Test" was always skiping the first test package. I was on an older version of Eclipse and SpringSource.

我有一个类似的问题。出于某种原因,“Run As -> jUnit Test”总是跳过第一个测试包。我使用的是旧版本的 Eclipse 和 SpringSource。

I moved back to Juno - Version: 4.2.1 and all my test run when I perform: "Run As -> jUnit Test. "

当我执行“Run As -> jUnit Test”时,我又回到了 Juno - 版本:4.2.1 和我所有的测试运行。

回答by Mike Nakis

I had the same problem. Eclipse would only recognize and run 5 out of my 9 tests. After much troubleshooting I found this trick to convince Eclipse to recognize the remaining tests: just open each file, hit space and then backspace to mark it as changed, and save it. Then, Eclipse will recognize it as a test.

我有同样的问题。Eclipse 只会识别并运行我的 9 个测试中的 5 个。经过大量的故障排除后,我发现这个技巧可以说服 Eclipse 识别剩余的测试:只需打开每个文件,按空格键,然后退格键将其标记为已更改,然后保存。然后,Eclipse 会将其识别为测试。