你能帮我避免主/从Ant构建设置中的kludging JUnit吗?

时间:2022-12-26 05:34:12

We're using the task within our master build to invoke targets in separate ant builds for each of our sub-projects. So far so good, we get things built, we can even run JUnit tasks within each one and everybody is happy. However...

我们在主构建中使用该任务来为每个子项目在单独的ant构建中调用目标。到目前为止一切顺利,我们可以构建内容,甚至可以在每个内部运行JUnit任务,每个人都很高兴。然而...

We want to take it to the next level, we would like to have a single JUnit report generated from the JUnit test result XML for all of our sub-projects but if we terminate the build whenever any of the sub-projects has a unit test failure, we never get to the point where we can generate a unified report. So that suggests that we would somehow note that unit tests failed within one or more of the sub-projects and not fail immediately but wait until the end of the master build to fail.

我们希望将它提升到一个新的水平,我们希望从所有子项目的JUnit测试结果XML生成一个JUnit报告,但是如果我们在任何子项目进行单元测试时终止构建失败,我们永远无法达到可以生成统一报告的程度。因此,这表明我们会以某种方式注意到单个测试在一个或多个子项目中失败并且不会立即失败,而是等到主构建结束失败。

What mechanism exists for that communication from the child builds up to the master build though? Properties are immutable and everything else we think of (properties files we update, files we touch, etc.) seem like horrible kludges. Is there a way to do this that fits in nicely with Ant and doesn't seem like something horrible we grafted on?

从子项构建到主构建的通信存在什么机制?属性是不可变的,我们想到的其他一切(我们更新的属性文件,我们触摸的文件等)看起来像是可怕的kludges。有没有办法做到这一点,与Ant很好地融合,似乎并不像我们嫁接的那些可怕的东西?

2 个解决方案

#1


The junit task supports the haltonerror and haltonfailure attributes, which, if set to false, will cause the ant script to continue to run even if a test fails. There is also an errorproperty and failureproperty you can set instead. You can then copy your junit reports to a master directory (with all success and failures), and use the fail task to fail if either of those properties have been set.

junit任务支持haltonerror和haltonfailure属性,如果设置为false,则会导致ant脚本继续运行,即使测试失败也是如此。您可以设置错误的属性和失败属性。然后,您可以将junit报告复制到主目录(包含所有成功和失败),如果已设置其中任何一个属性,则使用失败任务失败。

Something along the lines of:

有点像:

<target name="run-tests" >
    <junit printsummary="on" fork="yes" haltonfailure="false" haltonerror="false" errorproperty="test.failed" failureproperty="tests.failed" showoutput="true" maxmemory="512m">
        <classpath refid="classpath" />
        <formatter type="xml" />
        <batchtest todir="test/reports">
            <fileset dir="${build.classes.dir}">
                <patternset refid="testfiles" />
            </fileset>
        </batchtest>
    </junit>
    <copy todir="test/master/reports" dir="test/reports" />
    <fail if="tests.failed"/>
</target>

#2


OK, I never got an answer on this one that I liked that much but we did end up finding a good solution we like a lot. We switched from using Anthill OS as our build server to Hudson and after we did that we were able to take advantage of a Hudson feature where it will aggregate JUnit results from any number of locations to produce a single report that goes with each build (whether successful or not). So, in short, use Hudson. It rocks!

好吧,我从来没有得到过这个我非常喜欢的答案,但我们最终找到了一个我们非常喜欢的好解决方案。我们从使用Anthill OS作为我们的构建服务器切换到Hudson,在我们这样做之后,我们能够利用Hudson功能,它将从任意数量的位置聚合JUnit结果,以生成与每个构建一起的单个报告(无论是成功与否)。所以,简而言之,请使用Hudson。它摇滚!

#1


The junit task supports the haltonerror and haltonfailure attributes, which, if set to false, will cause the ant script to continue to run even if a test fails. There is also an errorproperty and failureproperty you can set instead. You can then copy your junit reports to a master directory (with all success and failures), and use the fail task to fail if either of those properties have been set.

junit任务支持haltonerror和haltonfailure属性,如果设置为false,则会导致ant脚本继续运行,即使测试失败也是如此。您可以设置错误的属性和失败属性。然后,您可以将junit报告复制到主目录(包含所有成功和失败),如果已设置其中任何一个属性,则使用失败任务失败。

Something along the lines of:

有点像:

<target name="run-tests" >
    <junit printsummary="on" fork="yes" haltonfailure="false" haltonerror="false" errorproperty="test.failed" failureproperty="tests.failed" showoutput="true" maxmemory="512m">
        <classpath refid="classpath" />
        <formatter type="xml" />
        <batchtest todir="test/reports">
            <fileset dir="${build.classes.dir}">
                <patternset refid="testfiles" />
            </fileset>
        </batchtest>
    </junit>
    <copy todir="test/master/reports" dir="test/reports" />
    <fail if="tests.failed"/>
</target>

#2


OK, I never got an answer on this one that I liked that much but we did end up finding a good solution we like a lot. We switched from using Anthill OS as our build server to Hudson and after we did that we were able to take advantage of a Hudson feature where it will aggregate JUnit results from any number of locations to produce a single report that goes with each build (whether successful or not). So, in short, use Hudson. It rocks!

好吧,我从来没有得到过这个我非常喜欢的答案,但我们最终找到了一个我们非常喜欢的好解决方案。我们从使用Anthill OS作为我们的构建服务器切换到Hudson,在我们这样做之后,我们能够利用Hudson功能,它将从任意数量的位置聚合JUnit结果,以生成与每个构建一起的单个报告(无论是成功与否)。所以,简而言之,请使用Hudson。它摇滚!