You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Alison Monteith <al...@edusoft.com> on 2004/10/07 23:17:21 UTC

Build not failing when Junit tests fail

Hi,
 
I'm pretty new to ant am trying to get our ant build to fail when any
junit test fails.
 
I've looked at our current build.xml and have found the following (which
appears to be correct):
 
target to run the tests contains:
 
 <junit printsummary="yes" fork="yes" haltonfailure="false"
failureproperty="junit_test_failed">
 
later target contains:
 
<fail if="junit_test_failed" message="Junit test failure"/>
 
When I use the Ant -debug option the failureproperty value is being set
to junit_test_failed as expected, but for some reason the build being
reported as successful.  If I take out the if="junit_test_failed"
statement.  ie.
just have: <fail message="Junit test failure"/>  then the build fails.
 
I'm thinking that somehow the junit_test_failed property is not visible
at the time of the <fail> tag.  
 
There are a lot of <ant call> statements in my build.xml, and it's in
one of these calls that the property is being set.  Why is this
junit_test_failed not visible when the <fail> tag is being executed.  
 
Here's excepts from my build.xml, for more details:
 
------------------------------------------
 <target name="test-cc" depends="clean, init, compile, compile-test"
   description="Runs all JUnit tests and cleans (used for
cruisecontrol)">
    <antcall target="run-tests">
        <param name="test.mask" value="Test"/>
    </antcall>
     </target>
 
---------------------------------------
  <target name="run-tests">
          -----------
        (snipped code)
           ----------
<foreach target="run-unit-test" param="test-name"
list="${rel.test.list}" />
<antcall target="junit-report"/>
 </target>
 
-----------------------------------------
<target name="run-unit-test">

          -----------
        (snipped code)
           ----------
<junit printsummary="yes" fork="yes" haltonfailure="false"
failureproperty="junit_test_failed">
     <jvmarg value="-Xdebug"/>
     <jvmarg value="-Xnoagent"/>
     <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n"/>
     <jvmarg value="-Djava.compiler=NONE"/>
     <classpath>
       <pathelement location="${test.source}"/>
       <path refid="project.classpath"/>
     </classpath> 
 
     <batchtest todir="${test.reports}">
        <fileset dir="${test.source}">
           <include name="${test-name}"/>
        </fileset>
        <formatter type="xml"/>
     </batchtest>
   </junit>
 </target>
 
---------------------------------------------
 <target name="junit-report">
    <junitreport todir="${test.reports}">
      <fileset dir="${test.reports}">
        <include name="TEST-*.xml" />
       </fileset>
       <report todir="${test.reports}" />
    </junitreport>
  <fail if="junit_test_failed" message="Junit test failure"/> 
  </target>
----------------------------------------------
 
Any help would really be appreciated!
 
Thanks,
 
Alison






 



Re: Build not failing when Junit tests fail

Posted by Ivan Ivanov <ra...@yahoo.com>.
Hi Alison,
I cannot tell you where your properties get confused
along the three <antcall>s (AFAIK antcall opens a
whole new properties namespace so one should play with
inherit attributes so that properties be visible in
the new namespace), but here is a more concise way to
do unit testing and then unit reporting:

<target name="test">
    <junit haltonfailure="false"
failureproperty="junit_failed"
errorproperty="junit_failed">
        <batchtest ....>
    </junit>

    <junitreport .../>
    <fail if="junit_failed" message="At least one test
failed"/>
</target>

The above snippet allows you to run your junit tests
and then create test reports and then if a test has
failed the build process fails.

HTH Ivan
--- Alison Monteith <al...@edusoft.com>
wrote:

> Hi,
>  
> I'm pretty new to ant am trying to get our ant build
> to fail when any
> junit test fails.
>  
> I've looked at our current build.xml and have found
> the following (which
> appears to be correct):
>  
> target to run the tests contains:
>  
>  <junit printsummary="yes" fork="yes"
> haltonfailure="false"
> failureproperty="junit_test_failed">
>  
> later target contains:
>  
> <fail if="junit_test_failed" message="Junit test
> failure"/>
>  
> When I use the Ant -debug option the failureproperty
> value is being set
> to junit_test_failed as expected, but for some
> reason the build being
> reported as successful.  If I take out the
> if="junit_test_failed"
> statement.  ie.
> just have: <fail message="Junit test failure"/> 
> then the build fails.
>  
> I'm thinking that somehow the junit_test_failed
> property is not visible
> at the time of the <fail> tag.  
>  
> There are a lot of <ant call> statements in my
> build.xml, and it's in
> one of these calls that the property is being set. 
> Why is this
> junit_test_failed not visible when the <fail> tag is
> being executed.  
>  
> Here's excepts from my build.xml, for more details:
>  
> ------------------------------------------
>  <target name="test-cc" depends="clean, init,
> compile, compile-test"
>    description="Runs all JUnit tests and cleans
> (used for
> cruisecontrol)">
>     <antcall target="run-tests">
>         <param name="test.mask" value="Test"/>
>     </antcall>
>      </target>
>  
> ---------------------------------------
>   <target name="run-tests">
>           -----------
>         (snipped code)
>            ----------
> <foreach target="run-unit-test" param="test-name"
> list="${rel.test.list}" />
> <antcall target="junit-report"/>
>  </target>
>  
> -----------------------------------------
> <target name="run-unit-test">
> 
>           -----------
>         (snipped code)
>            ----------
> <junit printsummary="yes" fork="yes"
> haltonfailure="false"
> failureproperty="junit_test_failed">
>      <jvmarg value="-Xdebug"/>
>      <jvmarg value="-Xnoagent"/>
>      <jvmarg
>
value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n"/>
>      <jvmarg value="-Djava.compiler=NONE"/>
>      <classpath>
>        <pathelement location="${test.source}"/>
>        <path refid="project.classpath"/>
>      </classpath> 
>  
>      <batchtest todir="${test.reports}">
>         <fileset dir="${test.source}">
>            <include name="${test-name}"/>
>         </fileset>
>         <formatter type="xml"/>
>      </batchtest>
>    </junit>
>  </target>
>  
> ---------------------------------------------
>  <target name="junit-report">
>     <junitreport todir="${test.reports}">
>       <fileset dir="${test.reports}">
>         <include name="TEST-*.xml" />
>        </fileset>
>        <report todir="${test.reports}" />
>     </junitreport>
>   <fail if="junit_test_failed" message="Junit test
> failure"/> 
>   </target>
> ----------------------------------------------
>  
> Any help would really be appreciated!
>  
> Thanks,
>  
> Alison
> 
> 
> 
> 
> 
> 
>  
> 
> 
> 



		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

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