Migrating from JUnit

请注意,org.testng.Assert类使用的参数顺序与JUnit使用的不同。如果您正在移植使用JUnit断言的代码,那么您可能需要使用该类的静态导入

import static org.testng.AssertJUnit.*;

TestNG可以自动识别和运行JUnit测试,因此您可以使用TestNG作为所有现有测试的转发器,并使用TestNG编写新的测试。

示例-用TestNG one替换JUnit Ant任务

<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true">

    <batchtest todir="${build.test.results.dir}">

        <fileset dir="${test.src.dir}">

            <include name="**/*Test.*"/>

    </batchtest>

    <classpath>

        <path path="${run.test.classpath}"/>

    </classpath>

    <syspropertyset>

        <propertyref prefix="test-sys-prop."/>

        <mapper from="test-sys-prop.*" to="*" type="glob"/>

    </syspropertyset>

    <formatter type="xml"/>

    <jvmarg value="-ea"/>

    <jvmarg line="${run.jvmargs}"/>

</junit>

testng配置文件为

 

<taskdef name="testng" classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}"/>

<fileset id="mixed.tests" dir="${test.src.dir}">

    <include name="**/*Test.*"/>

</fileset>

<testng mode="mixed" classfilesetref="mixed.tests" workingDir="${work.dir}" failureProperty="tests.failed" outputdir="${build.test.results.dir}">

    <classpath>

        <pathelement path="${build.test.classes.dir}"/>

        <pathelement path="${run.test.classpath}"/>

        <pathelement path="${junit.lib}"/>

    </classpath>

    <propertyset>

        <propertyref prefix="test-sys-prop."/>

        <mapper from="test-sys-prop.*" to="*" type="glob"/>

    </propertyset>

    <jvmarg line="${run.jvmargs}"/>

</testng>

 

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐