Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6064501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:17:15+00:00 2026-05-23T09:17:15+00:00

I have some unit tests running through Ant, and I’d like to be able

  • 0

I have some unit tests running through Ant, and I’d like to be able to run some cleanup code if the unit tests fail. I was looking for some sort of “finally” block, but I had no luck finding one. I’ve tried using errorproperty and if statements on tasks, but ant only accepts “true”, “on” and “yes” as true properties. A successfully executed task (on unix at least) returns 0, so I’ve had to construct a ridiculously elaborate apparatus:

<project name="TestBuild" default="build" basedir=".">
<target name="build" depends="truth,checkresult,cleanup" />

<target name="truth">
    <echo message="Running Truth" />
    <exec executable="false" errorproperty="testfailure"/>
</target>
<target name="checkresult">
    <condition property="testfailed">
        <not>
            <equals arg1="${testfailure}" arg2="0" />
        </not>
    </condition>
</target>
<target name="cleanup" if="testfailed">
    <echo message="cleanup" />
    <fail />
</target>

Is there any simpler way to do this? For one, this requires to tasks to complete, which seems ridiculous. It also means I’d have to call both of them after every block of unit tests, because I obviously can’t set failonerror as I normally would. In all, it’s a hacky, inelegant solution, and I’m hoping someone has better one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:17:15+00:00Added an answer on May 23, 2026 at 9:17 am

    Two possiblities

    -1-
    use some try/catch/finally construct for specific parts of your script
    you need some Ant Plugin that provides those features, f.e. =

    Flaka
    Antcontrib / Antelope

        <trycatch>
         <try>
          <exec .../>
         </try>
         <catch>
          do your cleanup here
          and afterwards don't forget to fail
          </fail message="......."/>
         </catch>
          optionally you may use a finally section also
         <finally>
          ..
         </finally>
       </trycatch>
    

    -2-
    use a buildlistener for the whole script ( BUILD SUCCESSFUL, BUILD FAILED )

    Kev Jackson has a nice example of an exec-listener in his presentation, = http://people.apache.org/~kevj/ossummit/extending-ant.html (the sources of the exec-listener are included in the slides)

    You’re able to kick off specific tasks depending on the build result after your build has finished

    <!-- taskcontainer -->    
    <exec-listener onSuccess="true|false">
    ..
    
     your stuff goes here 
    ..
    </exec-listener>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some unit tests set up in my PowerBuilder application that run through
We have some unit tests running against a SQL server 2000 database using the
I'm struggling getting some unit tests running and wondering if anyone might have anything
I am modifying a Nant build script to run some unit tests. I have
I have a class which has some unit tests, but when I am running
We have some scripts that we run as part of our unit tests. This
I have some unit tests that run fine on my dev machine on both
I have some MSTest unit tests that are running just fine on my machine
Currently I have some unit tests that I would like to be executed during
I have some unit tests that use Azure Storage. When running these locally, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.