带有Ant junitlauncher的JUnit 5:NoClassDefFoundError:org / junit / platform / launcher / core / Launcher
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有Ant junitlauncher的JUnit 5:NoClassDefFoundError:org / junit / platform / launcher / core / Launcher相关的知识,希望对你有一定的参考价值。
我想和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
其次是:
BUILD FAILED /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
我怎么能让它发挥作用?我错过了什么?
我遇到了同样的问题,直接在ant调用中手工处理libs,比如“ant -lib lib /”。
以上是关于带有Ant junitlauncher的JUnit 5:NoClassDefFoundError:org / junit / platform / launcher / core / Launcher的主要内容,如果未能解决你的问题,请参考以下文章
Ant、Ivy 和 JUnit 找不到类 - build.xml 中的错误?