java Netbeans:“运行 -> 测试项目”不做任何事情

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

Netbeans: "Run -> Test Project" doesn't do anything

javanetbeansantjunitnetbeans6.8

提问by java.is.for.desktop

I have many JUnit tests, which are all created by Netbeans' assistant (so nothing customized). I can run every test manuallyby doing "Test File" (Ctrl+F6).

我有很多 JUnit 测试,它们都是由 Netbeans 的助手创建的(所以没有定制)。我可以通过执行“测试文件”(Ctrl+F6)手动运行每个测试。

But when I use "Run -> Test Project", the message "No Tests executed" is displayed.

但是当我使用“运行 - > 测试项目”时,会显示消息“未执行测试”。

Do I have to register every JUnit test somewhere?
Or what could be the problem here?

我是否必须在某处注册每个 JUnit 测试?
或者这里可能有什么问题?

Before that, following appears in the output window:

在此之前,输出窗口中会出现以下内容:

init:
Deleting: /MY-WORK/my.data.adv/build/built-jar.properties
deps-jar:
Updating property file: /MY-WORK/my.data.adv/build/built-jar.properties
my.commons.init:
my.commons.deps-jar:
Updating property file: /MY-WORK/my.data.adv/build/built-jar.properties
my.commons.compile:
Copy libraries to /MY-WORK/my.commons/dist/lib.
my.commons.jar:
my.data.init:
my.data.deps-jar:
Updating property file: /MY-WORK/my.data.adv/build/built-jar.properties
my.data.compile:
Copy libraries to /MY-WORK/my.data/dist/lib.
my.data.jar:
compile:
compile-test:
test-report:
test:
BUILD SUCCESSFUL (total time: 0 seconds)

EDIT

编辑

  • The project type is "class library", nocustom configurations in build.xmlare used.

  • Perhaps it is relevant to mention, that the project is old (created with some Netbeans version prior to 6.7).

  • 项目类型为“类库”,不使用自定义配置build.xml

  • 也许值得一提的是,该项目很旧(使用 6.7 之前的某些 Netbeans 版本创建)。

回答by vkraemer

Since I submitted the correct clue necessary to generate an answer, I figure that I should add a bit of value to it...

由于我提交了生成答案所需的正确线索,因此我认为我应该为其添加一些价值......

If you create a Java->Class Library project with NetBeans, you can create a unit test associated with each of the classes in your project's Source Packages. You just need to right-click on the class in the Projects explorer.

如果使用 NetBeans 创建 Java->Class Library 项目,则可以创建与项目源包中的每个类相关联的单元测试。您只需要在项目资源管理器中右键单击该类。

If you are creating the 'first test' for a project, the IDE lets you choose between JUnit 3 and JUnit 4.

如果您要为项目创建“第一个测试”,IDE 允许您在 JUnit 3 和 JUnit 4 之间进行选择。

When you create a test for a.b.c.NewClass, NetBeans will allow you to name the test anything you want and put the test in any package you want... most of the time, you do not want to change the defaults that appear in the dialog (a.b.c.NewClassTest). In NetBeans 6.9 builds, a warning will appear if the name of the test you are about to create does not have "Test" as its suffix.

当您为 abcNewClass 创建测试时,NetBeans 将允许您将测试命名为您想要的任何名称并将测试放入您想要的任何包中......大多数情况下,您不想更改对话框中显示的默认值( abcNewClassTest)。在 NetBeans 6.9 版本中,如果您要创建的测试名称的后缀不是“Test”,则会出现警告。

If you create test class names that do not end with "Test", you can still get them to run when you use the Test action on a project. You just have to trigger them from a 'normal' test class.

如果您创建的测试类名称不以“Test”结尾,您仍然可以在对项目使用 Test 操作时让它们运行。您只需要从“正常”测试类中触发它们。

回答by java.is.for.desktop

Thanks to the user vkraemer!

感谢用户vkraemer

The solution is: Only JUnit tests are run when their name ends with Test.

解决方案是:仅当 JUnit 测试的名称以Test.

Section from build-impl.xmlproves it:

从节build-impl.xml证明它:

<target depends="init,compile-test,-pre-test-run"
    if="have.tests" name="-do-test-run">
  <j2seproject3:junit testincludes="**/*Test.java"/>
</target>

回答by Daniel

If you are using maven, you might want to check your surefire plugin on pom.xml

如果您使用的是 maven,您可能需要在 pom.xml 上检查您的 surefire 插件

...
 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.11</version>
            <configuration>
                <includes>
                    <include>**/*Test.java</include>                        
                </includes>
                <systemPropertyVariables>
                    <java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
                </systemPropertyVariables>
            </configuration>
        </plugin>


  ...

回答by Steve

My tests were working then they stopped, just displaying:

我的测试正在工作然后他们停止了,只是显示:

No tests executed.(0.0 s)

未执行任何测试。(0.0 秒)

The problem was an extra space in the VM Options:after the -D. This caused problems:

问题是VM Options:-D. 这导致了以下问题:

-D mysetting.home=something

and this fixed it:

这修复了它:

-Dmysetting.home=something