ant junit 未运行带有测试目标的单一方法

发布于 2025-01-16 20:06:36 字数 998 浏览 1 评论 0原文

我有一个运行 Ant 版本 1.10.6 的构建系统 我在下面总结的宏定义被构造为打开“run.multi”,它要么运行单个测试方法,要么执行其他操作(我没有将其包括在内,因为它不相关)。 我这里遇到的问题是,我无法让它只运行一种方法“test.method” - 我已经打开了详细功能,可以看到它全部进入并正确设置,但无论如何它都会运行所有方法!

    <echo level="info" message="Single method=@{test.method}" />
    
    <junit printsummary="on" showoutput="true" fork="yes" forkmode="once">
        <assertions>
            <enable/>
        </assertions>

        <test unless="${run.multi}"
                name="@{test.single}"               
                methods="@{test.method}"
                haltonfailure="no" 
                haltonerror="no">
            <formatter type="plain" usefile="false"/>
        </test>

这是输出的一部分:

[echo] Single method=testSimple
[junit] Running com.test.util.TheTestToRun
[junit] Testsuite: com.test.util.TheTestToRun
[junit] Running on Java 9.0.4
[junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.473 sec

I've got a build system running Ant Version 1.10.6
The macrodef that I've summarised below is constructed to switch on "run.multi" either it runs a single test method or it does something else (which i've not included as its not relevant).
The issue I have here is that I cannot get it to run just the one method 'test.method' - I've turned the verbose on and can see it all going in and being set correctly, but it runs all the methods regardless!

    <echo level="info" message="Single method=@{test.method}" />
    
    <junit printsummary="on" showoutput="true" fork="yes" forkmode="once">
        <assertions>
            <enable/>
        </assertions>

        <test unless="${run.multi}"
                name="@{test.single}"               
                methods="@{test.method}"
                haltonfailure="no" 
                haltonerror="no">
            <formatter type="plain" usefile="false"/>
        </test>

And here is a portion of the output:

[echo] Single method=testSimple
[junit] Running com.test.util.TheTestToRun
[junit] Testsuite: com.test.util.TheTestToRun
[junit] Running on Java 9.0.4
[junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.473 sec

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

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

发布评论

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

评论(1

调妓 2025-01-23 20:06:36

发生这种情况的原因要么是 ant 中的一个错误,要么是一个功能 - 围绕 junit 部分的 fork 选项。设置“fork=no”,问题就消失了:

    <junit printsummary="on" showoutput="true" fork="no" forkmode="once">
        <test unless="${run.multi}"
                name="@{test.single}"               
                methods="@{test.method}"
                haltonfailure="no" 
                haltonerror="no">
            <formatter type="plain" usefile="false"/>
        </test>

输出的一部分:

[junit] Running com.test.util.TheTestToRun
[junit] Testsuite: com.test.util.TheTestToRun
[junit] Running on Java 9.0.4
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.12 sec

The reason that this was happening is either a bug or a feature in ant - around the fork option on the junit section. set 'fork=no' and the issue goes away:

    <junit printsummary="on" showoutput="true" fork="no" forkmode="once">
        <test unless="${run.multi}"
                name="@{test.single}"               
                methods="@{test.method}"
                haltonfailure="no" 
                haltonerror="no">
            <formatter type="plain" usefile="false"/>
        </test>

A portion of the output:

[junit] Running com.test.util.TheTestToRun
[junit] Testsuite: com.test.util.TheTestToRun
[junit] Running on Java 9.0.4
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.12 sec
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文