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

发布于 2024-08-23 12:12:08 字数 1042 浏览 5 评论 0原文

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

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

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

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

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)

编辑

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

  • 也许需要提及的是,该项目是旧的(使用 6.7 之前的某些 Netbeans 版本创建的)。

    也许需要提及的是,

I have many JUnit tests, which are all created by Netbeans' assistant (so nothing customized). I can run every test manually by doing "Test File" (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?

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", no custom configurations in build.xml are used.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

戴着白色围巾的女孩 2024-08-30 12:12:08

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

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

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

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

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

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.

If you are creating the 'first test' for a project, the IDE lets you choose between JUnit 3 and 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.

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.

柠栀 2024-08-30 12:12:08

感谢用户vkraemer

解决方案是:只有名称以 Test 结尾的 JUnit 测试才会运行。

build-impl.xml 的部分证明了这一点:

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

Thanks to the user vkraemer!

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

Section from build-impl.xml proves it:

<target depends="init,compile-test,-pre-test-run"
    if="have.tests" name="-do-test-run">
  <j2seproject3:junit testincludes="**/*Test.java"/>
</target>
将军与妓 2024-08-30 12:12:08

如果您使用 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>


  ...

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

...
 <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>


  ...
命比纸薄 2024-08-30 12:12:08

我的测试工作正常,然后停止了,只显示:

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

问题是 VM Options:-D 后面有多余的空格。这导致了问题:

-D mysetting.home=something

这解决了它:

-Dmysetting.home=something

My tests were working then they stopped, just displaying:

No tests executed.(0.0 s)

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

-D mysetting.home=something

and this fixed it:

-Dmysetting.home=something
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文