我想结合 ant 执行 junit5 测试,特别是junitlauncher
这是我的项目结构:
这是我的构建文件:
<?xml version="1.0" encoding="UTF-8"?>
<project default="test" name="test">
<property name="src.dir" value="${basedir}/src" />
<property name="output.dir" value="${basedir}/build" />
<!-- PATH DEFINITIONS -->
<path id="junit5.classpath">
<fileset dir="${basedir}/lib/" />
</path>
<path id="test.classpath">
<path refid="junit5.classpath" />
<fileset dir="${output.dir}">
<include name="**/*.class" />
</fileset>
</path>
<target name="clean">
<delete dir="${output.dir}" />
</target>
<target name="compile" depends="clean">
<mkdir dir="${output.dir}" />
<mkdir dir="${output.dir}/report" />
<javac srcdir="${src.dir}" destdir="${output.dir}" includeantruntime="false">
<!-- test libs -->
<classpath>
<path refid="junit5.classpath" />
</classpath>
</javac>
</target>
<target name="test" depends="compile">
<pathconvert property="classpathProp" refid="test.classpath"/>
<echo>Classpath is ${classpathProp}</echo>
<echo>Running junit tests...</echo>
<junitlauncher>
<classpath refid="test.classpath" />
<test name="test.SomeClassTest" />
</junitlauncher>
</target>
</project>
当我尝试运行测试任务时,我可以看到类路径:
Classpath is
/Users/some-username/Documents/workspace/test/lib/junit-jupiter-api-5.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-jupiter-engine-5.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-jupiter-migrationsupport-5.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-jupiter-params-5.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-platform-commons-1.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-platform-engine-1.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-platform-launcher-1.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-platform-runner-1.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-platform-suite-api-1.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit-vintage-engine-5.3.0-SNAPSHOT.jar:
/Users/some-username/Documents/workspace/test/lib/junit.jar:
/Users/some-username/Documents/workspace/test/lib/org.apiguardian_1.0.0.v20180327-1502.jar:
/Users/some-username/Documents/workspace/test/lib/org.hamcrest.core_1.3.0.v20180420-1519.jar:
/Users/some-username/Documents/workspace/test/lib/org.opentest4j_1.0.0.v20180327-1502.jar:
/Users/some-username/Documents/workspace/test/build/test/SomeClass.class:
/Users/some-username/Documents/workspace/test/build/test/SomeClassTest.class:
/Users/some-username/Documents/workspace/test/build/test/TestSuite.class
其次是:
构建失败 /Users/some-username/Documents/workspace/test/build.xml:36: java.lang.NoClassDefFoundError: org/junit/platform/launcher/core/LauncherFactory
您可以在此处找到 Eclipse 项目存档:https ://drive.google.com/file/d/161rYTopmqM3JMqv8kvM6VjJbG1sm-3k2/view?usp=sharing
我怎样才能让它工作?我错过了什么?