首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ant不识别@ParametrizedTest和@CsvSource

ant不识别@ParametrizedTest和@CsvSource
EN

Stack Overflow用户
提问于 2019-01-31 06:34:23
回答 1查看 415关注 0票数 0

尽管添加了所需的依赖项,但我的ant (版本1.10.5)构建无法编译junit5测试

我已经将eclipse指向了在我的系统中单独安装的最新版本的Ant,并添加了junit官方页面中提到的所有jar文件--junit。

蚂蚁-junit样本页面获取的构建脚本如下:

代码语言:javascript
复制
     <?xml version="1.0" encoding="UTF-8"?>
        <project name="junit5-jupiter-starter-ant" default="build" basedir=".">

    <fail message="Ant 1.10.5 is required!">
        <condition>
            <not>
                <antversion atleast="1.10.5"/>
            </not>
        </condition>
    </fail>

    <path id="test.classpath">
        <pathelement path="build/test"/>
        <pathelement path="build/main"/>
        <fileset dir="${ant.home}/lib" includes="*.jar" />
    </path>

    <target name="build" description="clean build" depends="clean, test" />

    <target name="clean">
        <delete dir="build"/>
        <echo message="${ant.home}" />    </target>

    <target name="init">
        <mkdir dir="build/main"/>
        <mkdir dir="build/test"/>
        <mkdir dir="build/test-report"/>
    </target>

    <target name="compile" depends="init">
        <javac destdir="build/main" srcdir="src/main/java" includeantruntime="false"/>
        <javac destdir="build/test" classpathref="test.classpath" srcdir="src/test/java" includeantruntime="false"/>
    </target>

    <!-- https://junit.org/junit5/docs/snapshot/user-guide/#running-tests-build-ant -->
    <target name="test.junit.launcher" depends="compile">
        <junitlauncher haltOnFailure="true" printSummary="true">
            <classpath refid="test.classpath"/>
            <testclasses outputdir="build/test-report">
                <fileset dir="build/test">
                    <include name="**/*Tests.class"/>
                </fileset>
                <listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/>
                <listener type="legacy-plain" sendSysOut="true" />
            </testclasses>
        </junitlauncher>
    </target>

    <!-- https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher -->
    <target name="test.console.launcher" depends="compile">
        <java classpathref="test.classpath" classname="org.junit.platform.console.ConsoleLauncher" fork="true" failonerror="true">
            <arg value="--scan-classpath"/>
            <arg line="--reports-dir build/test-report"/>
        </java>
        <junitreport todir="build/test-report">
            <fileset dir="build/test-report">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="build/test-report/html"/>
        </junitreport>
    </target>

    <target name="test" depends="test.junit.launcher, test.console.launcher" />

</project>

但我遇到了错误

代码语言:javascript
复制
[javac] import org.junit.jupiter.params.ParameterizedTest;
    [javac]                                ^
     org.junit.jupiter.params.provider does not exist
    [javac] import org.junit.jupiter.params.provider.CsvSource;
    [javac]                                         ^
    [javac] CalculatorTests.java:31: error: cannot find symbol
    [javac]     @ParameterizedTest(name = "{0} + {1} = {2}")
    [javac]      ^
    [javac]   symbol:   class ParameterizedTest
    [javac]   location: class CalculatorTests
    [javac]  \CalculatorTests.java:32: error: cannot find symbol
    [javac]     @CsvSource({
    [javac]      ^
    [javac]   symbol:   class CsvSource
    [javac]   location: class CalculatorTests
    [javac] 4 errors

你能指点一下我需要做什么吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-31 07:02:26

junit5-jupiter-starter-ant示例将JUnit 5的“独立”JAR复制到$ANT_HOME/lib文件夹中。这个预置的Ant安装包括JUnit 5必须提供的所有包(平台、木星、Vintage),并通过class-path或其他方式将它们传递给蚂蚁运行时的任务:

代码语言:javascript
复制
wget --directory-prefix "${ant_folder}/lib" "...junit-platform-console-standalone-1.3.2.jar"

详细信息请参见build.shhttps://github.com/junit-team/junit5-samples/blob/master/junit5-jupiter-starter-ant/build.sh

所以,你可以:

  • junit-platform-console-standalone-${version}.jar复制到ANT_HOME/lib
  • 或者以与junit-jupiter-params-${version}.jar相同的方式添加junit-jupiter-api-${version}.jar
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54454657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档