需要帮助调试build.xml逻辑



下面是我的build.xml文件的代码片段,当测试目标失败时,预计将重新运行相同的测试目标,但控制不会在测试失败时重试逻辑,不确定我在这里缺少什么

    <!-- US Beta Target -->
    <target name="test-integration-assert-beta">
       <test-environment country="US" stage="Beta" host.name="URL Goes Here" emailid="" password="" company="" invalidpassword="" materialset=""/>
           <echo message="integTest.failure = ${integTest.failure}" />
           <echo message="failedTests = ${failedTests}" />
           <condition property="failedTests">
               <and>
                   <istrue value="${integTest.failure}" />
                   <available file="${integ.test.dir}/testng-failed.xml" />
               </and>
           </condition>
           <antcall target="test-integration-assert-beta-rerun">
           </antcall>
    </target>   
    <!-- US Beta Target (Re-run) -->
        <target name="test-integration-assert-beta-rerun" description="Rerunning Failed Beta Tests" if="failedTests">
           <echo message="Running Failed Integration Tests..." />
           <echo message="rerunFailedTests.failure = ${rerunFailedTests.failure}" />
           <copy file="${output.dir}/brazil-integ-tests/testng-failed.xml"
              tofile="${output.dir}/testng-failed.xml" />
       <test-environment country="US" stage="Beta" host.name="URL Goes Here" emailid="" password="" company="" invalidpassword="" materialset=""/>
           <echo message="rerunFailedTests.failure = ${rerunFailedTests.failure}" />
           <fail message="Tests Failed on rerun">
               <condition>
                   <istrue value="${rerunFailedTests.failure}" />
               </condition>
           </fail>
        </target>

<antcall>有时可能很有用,但是它有很多陷阱,使得脚本难以推理。特别是,<antcall>与Ant的正常依赖流冲突。

代替<antcall>,考虑使用<target depends="..."><macrodef>:

  • <target>depends属性开启条件逻辑。
  • <macrodef>允许代码重用,减少代码重复。
下面的build.xml给出了一个例子:
<project name="ant-macrodef-retry" default="run">
    <macrodef name="my-test-environment">
        <attribute name="try"/>
        <sequential>
            <echo>Call test-environment here.</echo>
            <!-- The following <condition> tasks are just for testing purposes. -->
            <!-- The real <test-environment> would set these properties. -->
            <condition property="integTest.failure" value="true">
                <and>
                    <equals arg1="@{try}" arg2="1"/>
                    <isset property="failTry1"/>
                </and>
            </condition>
            <condition property="rerunFailedTests.failure" value="true">
                <and>
                    <equals arg1="@{try}" arg2="2"/>
                    <isset property="failTry2"/>
                </and>
            </condition>
        </sequential>
    </macrodef>
    <target name="try1">
        <my-test-environment try="1"/>
        <echo message="integTest.failure = ${integTest.failure}" />
        <condition property="failedTests">
            <istrue value="${integTest.failure}" />
        </condition>
    </target>
    <target name="try2" if="failedTests">
        <echo message="Running Failed Integration Tests..." />
        <my-test-environment try="2"/>
        <echo message="rerunFailedTests.failure = ${rerunFailedTests.failure}" />
        <fail message="Tests Failed on rerun">
            <condition>
                <istrue value="${rerunFailedTests.failure}" />
            </condition>
        </fail>
    </target>
    <target name="run" depends="try1,try2"/>
</project>

输出

下面是上述Ant脚本的各种测试。它显示了脚本在各种故障场景中的行为…

=================================
Test command line: ant
try1:
     [echo] Call test-environment here.
     [echo] integTest.failure = ${integTest.failure}
try2:
run:
BUILD SUCCESSFUL
=================================
Test command line: ant -DfailTry1=true
try1:
     [echo] Call test-environment here.
     [echo] integTest.failure = true
try2:
     [echo] Running Failed Integration Tests...
     [echo] Call test-environment here.
     [echo] rerunFailedTests.failure = ${rerunFailedTests.failure}
run:
BUILD SUCCESSFUL
=================================
Test command line: ant -DfailTry1=true -DfailTry2=true
try1:
     [echo] Call test-environment here.
     [echo] integTest.failure = true
try2:
     [echo] Running Failed Integration Tests...
     [echo] Call test-environment here.
     [echo] rerunFailedTests.failure = true
BUILD FAILED
C:antbuild.xml:35: Tests Failed on rerun

相关内容

  • 没有找到相关文章

最新更新