Android JUnit测试失败,而不是像我期望的那样破坏我的Ant脚本?

Mar*_*ady 11 ant junit android

失败的JUnit测试,没有像我期望的那样破坏我的Ant脚本?

我的持续集成服务器运行一个Ant脚本,它调用类似:/ tests/ant run-tests

我的JUnit测试运行,但有错误:run-tests:[echo] run-tests-helper.[echo]运行测试... [exec] [exec] com.zedray.stuff.FooBarTest:.... [exec] com.zedray.stuff.FooBarTest:..... INSTRUMENTATION_RESULT:shortMsg =你的一些错误码.[exec] INSTRUMENTATION_RESULT:longMsg = java.security.InvalidParameterException:代码中的一些错误[exec] INSTRUMENTATION_CODE:0

错误是可以的,但是我的构建脚本继续运行(最终将我破碎的应用程序发布给我的测试人员 - 糟糕!).我期望的是instrimentaiton抛出构建错误,所以我的持续集成服务器(在这种情况下是TeamCity)意识到出错了并报告了破坏的构建."failonerror"已在相关的macrodef中设置,所以我不确定我还能做什么?

/tests/build.xml

运行测试......

关于如何解决这个问题的任何想法/建议?

问马克

Blu*_*ell 12

我是用另一种方式做的,因为我正在使用Android文件中的ant test目标.此目标打印到标准输出,因此我将stndout捕获到文件中,然后查询该文件,使用此结果使我的任务失败. build.xml

 <target name="run-acceptance-tests" depends="clean, debug, install" >

    <property name="log.file" value="acceptance_tests_standard_out.txt" />
    <!-- because we don't have control over the 'test' target (to check for passes an fails) this prints to standard out
         we capture standard out into a file and query this to see if we have any test failures, using this to pass/fail our task -->
    <record name="${log.file}" action="start" />
    <antcall target="test" />
    <record name="${log.file}" action="stop" />

    <!-- do other stuff -->

    <loadfile property="tests.output" srcFile="${log.file}" />

    <echo>Checking for failures</echo>
    <fail message="acceptance tests failed!" >
        <condition>
            <contains string="${tests.output}" substring="FAILURES" />
        </condition>
    </fail>

    <echo>acceptance tests passed!</echo>
</target>
Run Code Online (Sandbox Code Playgroud)


Ale*_*x B -3

ant JUnit 任务默认运行所有测试。对此有两种解决方案。

最简单的解决方案是将属性设置haltonerror为 true,构建将在第一次测试失败时失败。

稍微复杂一些(也是我的偏好)是设置failureProperty以便所有测试都运行。这可以让您知道有多少测试失败,而不仅仅是第一个失败的测试。这需要更多的 ant 工作,因为您需要在 junit 测试后添加一行,如下所示:

<fail message="tests failed" if="failureProperty"/>   
Run Code Online (Sandbox Code Playgroud)