Linux下Ant Junit安装配置及完成单元测试(2)


<!--
        <target depends="compile">
<jar jarfile="${hello_jar}" basedir="${dest}"/>
        </target>
  -->

<target depends="compile">
<java classname="HelloWorld" classpath="${dest}"/>
</target>
       
         <target depends = "compile">
          <junit printsummary="yes" >
          <formatter type="plain"/>
          <classpath path="${dest}"/>
          <test name = "HelloWorldTest"/>
</junit>
         </target>
        
</project>


       关于ant的xml语法,还是上网查吧。说不清楚,其中<classpath path="${dest}"/>是你要测试的class文件夹,<test name = "HelloWorldTest"/>是你要测试的文件。


        到这里总是完成了。。。。。

运行测试可以使用ant test。。运行完会生成运行报告,我故意弄错的测试,结果如下

Testsuite: HelloWorldTest
Tests run: 2, Failures: 2, Errors: 0, Time elapsed: 0.007 sec


Testcase: testgetInt took 0.002 sec
FAILED
expected:<6> but was:<5>
junit.framework.AssertionFailedError: expected:<6> but was:<5>
at HelloWorldTest.testgetInt(Unknown Source)


Testcase: testSayHello took 0 sec
FAILED
expected:<Hello[]World> but was:<Hello[ ]World>
junit.framework.ComparisonFailure: expected:<Hello[]World> but was:<Hello[ ]World>
at HelloWorldTest.testSayHello(Unknown Source)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwgsdy.html