You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Thomas L Roche <tl...@us.ibm.com> on 2005/11/11 22:34:17 UTC

testing ant failure

<Apologies in advance for cross-posting, but I couldn't decide which
list was more appropriate.>

How to test that an ant script fails appropriately? Specifically:

I'm working on a build app (a java app for building lots of different
things in lots of different places) that basically {creates, shleps,
invokes} ant scripts. I have a few JUnit tests on the app (and am
writing more). I'm hooking in a scanner that causes a build to fail if
a build prerequisite is not found. I know the scanner works because I
can manually

* move a prereq file so that it's not where the build expects it

* see the BUILD FAILED message corresponds to the message attribute of
  the appropriate <fail> task

(Unfortunately existing, downstream tests in the current suite (that
look for the appropriate build outputs) don't fail: they greenbar (in
eclipse's runner), presumably because they don't run.)

I'd prefer to automate this, e.g. to create one or more separate
suites with

* setUp() that sets up the prereqs not-quite-correctly, then invokes
  the build

* a testBuildFailed() that checks for failure

* a testBuildFailedAppropriately() that checks for appropriate failure

What's the "best way" to test for appropriate failure? The only thing
that comes to my mind is to parse the logfile, e.g.

* check for a "BUILD FAILED" line

* check that a line after the "BUILD FAILED" line contains the
  appropriate failure message.

Is there an easier/better way? Note that I do have access to the app
code and scripts, and I am more-than-willing to instrument them for
testability.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: [junit] testing ant failure

Posted by Stefan Bodewig <st...@freenet.de>.
On Fri, 11 Nov 2005, Thomas L. Roche <tl...@us.ibm.com> wrote:

> What's the "best way" to test for appropriate failure? The only
> thing that comes to my mind is to parse the logfile, e.g.
> 
> * check for a "BUILD FAILED" line
> 
> * check that a line after the "BUILD FAILED" line contains the
>   appropriate failure message.
> 
> Is there an easier/better way?

Take a look at Ant's own unit tests.  There is a BuildFileTest base
class that many tests extend with helper methods like
expectSpecificBuildException() which assert an Ant build fails.

Another alternative, and Ant itself is probably heading to this, is
the newer AntUnit test framework/antlib, that can be found in Ant's
svn repository in the sandbox (which it probably is going to leave in
order to become a real Ant subproject rather soon).

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: testing ant failure

Posted by Ninju Bohra <ni...@yahoo.com>.
Have you looked at the BuildFileTest class (part of the ant-testutil.jar) that has some helpful methods to determine whether a build file fails for the "right" reason.
 
My test methods are like:
 
    public void testMissingInputDateFailure() {
        expectSpecificBuildException("missingInputDateFailure", "missing inputDate attribute", "Both inputDate and dateFormat need to be defined or both need to be null");
    }

Look that the code of the class for futher details but basically you pass the target name you want call (i.e. one that you expect to fail) and it verifies that the short and long message on the exception are what you want.
 
Hope that help avoid re-writing stuff

Thomas L Roche <tl...@us.ibm.com> wrote:
list was more appropriate.>

How to test that an ant script fails appropriately? Specifically:

I'm working on a build app (a java app for building lots of different
things in lots of different places) that basically {creates, shleps,
invokes} ant scripts. I have a few JUnit tests on the app (and am
writing more). I'm hooking in a scanner that causes a build to fail if
a build prerequisite is not found. I know the scanner works because I
can manually

* move a prereq file so that it's not where the build expects it

* see the BUILD FAILED message corresponds to the message attribute of
the appropriate task

(Unfortunately existing, downstream tests in the current suite (that
look for the appropriate build outputs) don't fail: they greenbar (in
eclipse's runner), presumably because they don't run.)

I'd prefer to automate this, e.g. to create one or more separate
suites with

* setUp() that sets up the prereqs not-quite-correctly, then invokes
the build

* a testBuildFailed() that checks for failure

* a testBuildFailedAppropriately() that checks for appropriate failure

What's the "best way" to test for appropriate failure? The only thing
that comes to my mind is to parse the logfile, e.g.

* check for a "BUILD FAILED" line

* check that a line after the "BUILD FAILED" line contains the
appropriate failure message.

Is there an easier/better way? Note that I do have access to the app
code and scripts, and I am more-than-willing to instrument them for
testability.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org





		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.