蚂蚁无条件地执行任务? [英] Unconditionally execute a task in ant?

查看:126
本文介绍了蚂蚁无条件地执行任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图定义发出当目标完成执行,不管这个目标是否成功与否(使用echo)信息的任​​务。具体来说,目标执行运行一些单元测试的任务,我想发出一个信息,表明那里的结果是可用的:

I'm trying to define a task that emits (using echo) a message when a target completes execution, regardless of whether that target was successful or not. Specifically, the target executes a task to run some unit tests, and I want to emit a message indicating where the results are available:

<target name="mytarget">
  <testng outputDir="${results}" ...>
    ...
  </testng>
  <echo>Tests complete.  Results available in ${results}</echo>
</target>

不幸的是,如果测试失败,则任务失败和执行中止。因此,该消息是,如果通过测试只能输出 - 我想的正好相反。我知道我可以把任务的任务之前,而这将使用户更容易错过此消息。正是我试图做可能吗?

Unfortunately, if the tests fail, the task fails and execution aborts. So the message is only output if the tests pass - the opposite of what I want. I know I can put the task before the task, but this will make it easier for users to miss this message. Is what I'm trying to do possible?

更新:原来我是哑巴。我在与LT有haltOnFailure =真; TestNG的&GT;的任务,这也解释了我所看到的行为。现在的问题是,这种设置为false会导致整体的Ant构建成功,即使测试失败,这不是我想要的。下面使用任务的答案看起来可能是我想要的。

Update: It turns out I'm dumb. I had haltOnFailure="true" in my <testng> task, which explains the behaviour I was seeing. Now the issue is that setting this to false causes the overall ant build to succeed even if tests fail, which is not what I want. The answer below using the task looks like it might be what I want..

推荐答案

你的问题的解决方案是使用 failureProperty 会同在 haltOnFailure 这样TestNG的任务属性:

The solution to your problem is to use the failureProperty in conjunction with the haltOnFailure property of the testng task like this:

<target name="mytarget">
  <testng outputDir="${results}" failureProperty="tests.failed" haltOnFailure="false" ...>
    ...
  </testng>
  <echo>Tests complete.  Results available in ${results}</echo>
</target>

然后,在其他地方,当你想构建失败,你添加的蚂蚁code是这样的:

Then, elsewhere when you want the build to fail you add ant code like this:

<target name="doSomethingIfTestsWereSuccessful" unless="tests.failed">
   ...
</target>

<target name="doSomethingIfTestsFailed" if="tests.failed">
   ...
   <fail message="Tests Failed" />
</target>

您可以调用doSomethingIfTestsFailed您要Ant构建失败。

You can then call doSomethingIfTestsFailed where you want your ant build to fail.

这篇关于蚂蚁无条件地执行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆