首页 > 解决方案 > Ant junitlauncher 任务不运行测试

问题描述

我有一个 ant 目标可以通过以下方式运行 junit5 测试junitlauncher

    <target name="juint" depends="build">
        <mkdir dir="${junit.output.dir}" />
        <junitlauncher haltOnFailure="true" printSummary="true">
            <!-- include the app code & libraries required to run the tests -->
            <classpath>
                <path refid="datastudio-trunk-java-lib.classpath" />
                <pathelement location="target/classes"/>
            </classpath>

            <classpath>
                <!-- the test classes themselves -->
                <pathelement location="target/test-classes"/>
            </classpath>
            <testclasses outputdir="${junit.output.dir}">
                <fileset dir="target/test-classes">
                    <include name="**/*.class"/>
                </fileset>
                <listener type="legacy-brief" sendSysOut="true"/>
                <listener type="legacy-xml" sendSysErr="true" sendSysOut="true"/>
            </testclasses>
        </junitlauncher>
    </target>

正如我们在输出中看到的那样,该任务找到了我的测试,但没有运行它们:

[junitlauncher] Test run finished after 31 ms
[junitlauncher] [         2 containers found      ]
[junitlauncher] [         0 containers skipped    ]
[junitlauncher] [         0 containers started    ]
[junitlauncher] [         0 containers aborted    ]
[junitlauncher] [         0 containers successful ]
[junitlauncher] [         0 containers failed     ]
[junitlauncher] [         5 tests found           ]
[junitlauncher] [         0 tests skipped         ]
[junitlauncher] [         0 tests started         ]
[junitlauncher] [         0 tests aborted         ]
[junitlauncher] [         0 tests successful      ]
[junitlauncher] [         0 tests failed          ]

我有一个简单的 junit 测试类,它定义了 5 个这样的测试:

@RunWith(JUnitPlatform.class)
class JDBC {

    private static Logger log = null;

    @BeforeAll
    public static void setLogger() throws MalformedURLException {
        System.setProperty("log4j.configurationFile", "../log4j2.xml");
        log = LogManager.getLogger("fr.data.datastudio.test");
        log.info("logging enabled");
    }

    // [...]

    @Test
    void testSqlite() {
        Jdbc4Jni db = connect("org.sqlite.JDBC", "jdbc:sqlite::memory:", null, null);
        _testTypes(db);
    }
}

测试在 eclipse Junit 视图中运行正常,但不是从 ant。有谁知道为什么他们被发现但没有开始(也没有跳过)?

标签: antjunit5

解决方案


推荐阅读