tags:

views:

1030

answers:

2

I'm running CrossCheck (browserless js unit testing) as part of an ant script. I'd like ant to report failure if the CrossCheck tests fail. Here's the relevant bit from the build.xml

<target name="test" depends="concat">
    <java jar="src/test/lib/crosscheck.jar" fork="true">
        <arg value="src/test/webapp/js/"/>
    </java>

And an example of CrossCheck's failure messaging:

 [java] Running tests in environment: Mozilla 1.7 (Firefox 1.0)
 [java] org.mozilla.javascript.EcmaError: ReferenceError: "clusterNode" is not defined. (ResultXMLWrapperTest.js#22)
 [java]     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3229)
 [java]     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3219)
 [java]     at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3292)
 [java]     at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1636)
 [java]     at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1575)
 [java]     at org.mozilla.javascript.gen.c1._c1(ResultXMLWrapperTest.js:22)
 [java]     at org.mozilla.javascript.gen.c1.call(ResultXMLWrapperTest.js)
 [java]     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
 [java]     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
 [java]     at org.mozilla.javascript.gen.c1.call(ResultXMLWrapperTest.js)
 [java]     at net.thefrontside.crosscheck.framework.AbstractScopeFactory$1.run(AbstractScopeFactory.java:108)
 [java]     at org.mozilla.javascript.Context.call(Context.java:515)
 [java]     at org.mozilla.javascript.Context.call(Context.java:450)
 [java]     at net.thefrontside.crosscheck.framework.AbstractScopeFactory.initTestScope(AbstractScopeFactory.java:94)
 [java]     at net.thefrontside.crosscheck.framework.DefaultScopeFactory.getTestScope(DefaultScopeFactory.java:68)
 [java]     at net.thefrontside.crosscheck.framework.TestCase$1.run(TestCase.java:119)
 [java]     at org.mozilla.javascript.Context.call(Context.java:528)
 [java]     at org.mozilla.javascript.Context.call(Context.java:450)
 [java]     at net.thefrontside.crosscheck.framework.TestCase.run(TestCase.java:117)
 [java]     at net.thefrontside.crosscheck.framework.TestSuite.run(TestSuite.java:95)
 [java]     at net.thefrontside.crosscheck.framework.Crosscheck.runAll(Crosscheck.java:116)
 [java]     at net.thefrontside.crosscheck.framework.ConsoleRunner.run(ConsoleRunner.java:140)
 [java]     at net.thefrontside.crosscheck.framework.ConsoleRunner.main(ConsoleRunner.java:300)
 [java] ReferenceError: "clusterNode" is not defined. (ResultXMLWrapperTest.js#22)
 [java] Java Result: 1

Can ant get at the results of the CrossCheck test (perhaps Java Result: 1 gets passed back to ant?) and succeed or fail based on that?

+8  A: 

Assuming that CrossCheck returns a non-zero return code on a error you could add the failonerror attribute to the java task:

<target name="test" depends="concat">
    <java jar="src/test/lib/crosscheck.jar" fork="true" failonerror="true">
        <arg value="src/test/webapp/js/"/>
    </java>

See the documentation on the Ant Java task.

mtpettyp
awesome. thanks.
morgancodes
A: 

You can use the 'failonerror' attribute of the 'java' task.

failonerror Stop the buildprocess if the command exits with a returncode other than 0. Default is "false" (see note)

Check the manual here http://ant.apache.org/manual/CoreTasks/java.html

Vinnie