【问题标题】:Junit Ant Integration ProblemsJunit Ant 集成问题
【发布时间】:2023-03-18 21:34:01
【问题描述】:

我有一个单独的 junit 测试用例,它与 ant 脚本集成在一起。单独的junit工作正常,测试用例通过。当它与 ant 集成一起执行时,它会失败。

测试用例和ant脚本如下,

import org.junit.Test;

public class SimpleTest 
{

    @Test
    public void testHello()
    {
        System.out.println("Hello");
    }


}

蚂蚁脚本是,

<property file="build.properties" />

<path id="libirary">

    <fileset dir="${lib}">
        <include name="**.*jar" />
    </fileset>

</path>




<target name="clean">
    <delete dir="${build.classes.dir}" />
    <delete dir="${build.dir}" />
    <delete dir="${dist.dir}" />
</target>

<target name="init" depends="clean">
    <mkdir dir="${build.classes.dir}" />
    <mkdir dir="${dist.dir}" />
</target>


<target name="compile" depends="init">
    <javac encoding="ISO-8859-1" destdir="${build.classes.dir}" srcdir="${src.dir}">
        <classpath>
            <path refid="libirary" />
        </classpath>
    </javac>
</target>

<target name="jar" depends="compile">

    <jar destfile="${dist.dir}/${jar.filename}.jar">

        <fileset dir="${build.classes.dir}" />
        <zipfileset dir="${lib}" includes="**/*.jar" />

        <manifest>
            <attribute name="Main-Class" value="${main.file.name}" />
        </manifest>

    </jar>
</target>


<target name="junit" depends="compile">
    <junit   printsummary="yes" description="true" filtertrace="yes" >

        <classpath path="${lib}">
            <path refid="libirary" />
        </classpath>
        <test name="SimpleTest">
        </test>
    </junit>
</target>

输出是,

Buildfile: D:\Workspaces\TrunkForCheckIn-31-05-2013\PG\build.xml
clean:
   [delete] Deleting directory 
   [delete] Deleting directory 
   [delete] Deleting directory 
init:
    [mkdir] Created dir: 
    [mkdir] Created dir: 
compile:
    [javac]  warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 57 source files to 
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
junit:
    [junit] Running SimpleTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Test com.bosch.in.stepage.pg.SimpleTest FAILED
BUILD SUCCESSFUL
Total time: 1 second

【问题讨论】:

    标签: ant junit


    【解决方案1】:

    尝试添加一个普通的格式化程序:

    <target name="junit" depends="compile">
        <junit   printsummary="yes" description="true" filtertrace="yes" >
        <formatter type="plain" usefile="false" />
            <classpath path="${lib}">
                <path refid="libirary" />
            </classpath>
            <test name="SimpleTest">
            </test>
        </junit>
    </target>
    

    【讨论】:

    • 感谢您的回复您好 从冗长中我发现类未找到异常是原因,即使在给出以下代码后,它也没有拿起类,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 2011-08-17
    • 2011-02-17
    • 2010-11-11
    • 2015-08-20
    • 2011-10-22
    相关资源
    最近更新 更多