首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我在ant下的测试用例总是运行两次?

问为什么我在ant下的测试用例总是运行两次?
EN

Stack Overflow用户
提问于 2013-11-26 10:35:33
回答 1查看 2.6K关注 0票数 1

我正在尝试配置使用Ant的webdriver+testNG。这是一个简单的测试用例,启动FF并打开http://www.google.com。但是当我用ant执行build.xml时,测试用例执行了两次!这对我来说是个谜,我怀疑"Ant套件“中有什么问题,我不知道如何禁用it.here是我的代码。

Eclipse控制台输出:

代码语言:javascript
复制
    init:
    compile:
    [javac] D:\Workspace\HelloAnt\build.xml:23: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
run_tests:
     [echo] running tests
   [testng] ...
   [testng] ... TestNG 6.8beta 20120825_1010 by C?dric Beust (cedric@beust.com)
   [testng] ...
   [testng] [TestNG] Running:
   [testng]   D:\Workspace\HelloAnt\src\example\testng.xml
   [testng] ===============================================
   [testng] reportng demo
   [testng] Total tests run: 1, Failures: 0, Skips: 0
   [testng] ===============================================
   [testng] [TestNG] Running:
   [testng]   Ant suite
   [testng] ===============================================
   [testng] Ant suite
   [testng] Total tests run: 1, Failures: 0, Skips: 0
   [testng] ===============================================
     [echo] zip
      [zip] Building zip: D:\Workspace\HelloAnt\test-output\html.zip
BUILD SUCCESSFUL
Total time: 38 seconds

testng.xml代码:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<suite name="reportng demo" verbose="2">
<test name="test">
        <classes>
            <class name="example.NewTest">
                <methods>
                    <include name="setup"/>
                    <include name="verifyTitle"/>
            <include name="clean"/>
                </methods>
            </class>
        </classes>
    </test>
</suite>

和build.xml代码:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<project name="HelloReportng" default="run_tests" basedir=".">
    <property name="src" value="src" />
    <property name="dest" value="classes" />
    <property name="hello_jar" value="NewTest.jar" />
    <property name="lib.dir" value="lib" />
    <property name="output.dir" value="test-output"/>
    <property name="testng.dir" value="D:/Workspace/testng.jar"/>

    <!-- import testng jar package -->
    <taskdef resource="testngtasks" classpath="${testng.dir}"/>

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

    <target name="init">
       <mkdir dir="${dest}" />
    </target>

    <target name="compile" depends="init">    
       <javac srcdir="${src}" destdir="${dest}" >
           <classpath refid="test.classpath"/>           
       </javac>
    </target>

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

    <target name="run" depends="compress">
       <java classname="example.NewTest"   >
           <classpath refid="test.classpath"/>
       </java>      
    </target> 

    <target name ="clean">
        <delete dir="${dest}" />
        <delete dir="${hello_jar}" />
    </target>

    <target name="return" depends="clean">
        <ant target="clean" />
        <ant target="run" />
    </target>

    <!-- run tests -->
    <target name="run_tests" depends="compile">
        <echo>running tests</echo>
        <testng classpathref="test.classpath" outputdir="${output.dir}" haltonfailure="true" usedefaultlisteners="false"
         listeners="org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter"  failureproperty="test.failed" > 
        <classfileset dir="${dest}" includes="**/*.class" />
        <sysproperty key="org.uncommons.reportng.title" value="All Page Tests"></sysproperty>
        <sysproperty key="org.uncommons.reportng.escape-output" value="off"></sysproperty>
        <xmlfileset dir="${src}/example" >
            <include name="testng.xml" />
        </xmlfileset>
        </testng>
        <echo>zip</echo>
        <zip destfile="${output.dir}/html.zip" basedir="test-output/html" includes="**/*"></zip>
        <fail message="test failed.." if="test.failed" />
    </target>

</project>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-27 06:45:58

为什么你有两个目标- run_tests和run?我认为这是跑步的目标才是问题所在。移除目标,看看它是否有效。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20214622

复制
相关文章

相似问题

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