ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-...@ehatchersolutions.com>
Subject Re: simple ant and junit fails
Date Mon, 07 Jan 2002 02:21:30 GMT
Try out more of the <junit> options.

Here's a good start:

<junit printsummary="yes" haltonfailure="true">
  <formatter type="brief" usefile="false"/>
  .
  .
  .
</junit>

Don't let it say "BUILD SUCCESSFUL" (haltonfailure is one way to achieve
this) if tests failed!  :)

The "brief" formatter will display more details.

Now that you have Ant plugged in you can get rid of the 'main' method and
the other test runners.  Ant is now your test runner, always.  :))

<junit> does not involve the text or Swing test runners, it calls them
through JUnit's API more directly, but its the same mechanism.  Perhaps its
a classpath issue.

Also, don't forget about 'ant -debug'.

    Erik

p.s. from the code you provided below, it looks like  you'd get a compile
error because of a missing "{" on your test1 method.  Maybe thats just an
error in the cut-n-paste or something though.




----- Original Message -----
From: "Ray Tayek" <rtayek@mediaone.net>
To: "Ant Users List" <ant-user@jakarta.apache.org>
Sent: Sunday, January 06, 2002 8:31 PM
Subject: Re: simple ant and junit fails


> At 08:02 PM 1/6/02 -0500, you wrote:
> >If you drop all your dependent JAR's into ANT_HOME/lib (i.e. put
junit.jar
> >there) then you can (and should) run without a system specified
classpath.
> >
> >So, just put junit.jar in your Ant installations lib directory and all
> >should be well.
>
> works great!
>
> using the build below, it now says:
>
> Buildfile: build.xml
>
> init:
>
> compile:
>
> test:
>      [junit] Running MainTest
>      [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
>      [junit] TEST MainTest FAILED
>
> dist:
>
> BUILD SUCCESSFUL
>
> not sure why it says: Errors: 1, the test runs fine from the command line
> sans ant. (prints out OK). is the junit step invoking some method in a
> different way than: junit.textui.TestRunner.run(suite());?
>
> thanks
>
> import junit.framework.*;
> import junit.swingui.*;
> public class MainTest extends TestCase
>          {
>          public MainTest(String name) { super(name); }
>          public void test1()  assertNotNull(new Main()); }
>          public static Test suite() { return new
TestSuite(MainTest.class); }
>          private void run_(String[] argument)
>                  {
>                  if(true)
>                          junit.textui.TestRunner.run(suite());
>                          else
>                          { String[] string={ getClass().getName() };
> junit.swingui.TestRunner.main(string); }
>                  }
>          public static void main(String[] argument) { (new
> MainTest("run_")).run_(argument); }
>          }
>
> <project name="MyProject" default="dist" basedir=".">
>    <property name="src" value="."/>
>    <property name="build" value="build"/>
>    <property name="dist"  value="dist"/>
>    <property name="test"  value="test"/>
>    <target name="init">
>      <tstamp/>
>      <mkdir dir="${build}"/>
>    </target>
>    <target name="compile" depends="init">
>      <javac srcdir="${src}" destdir="${build}"
> classpath=".;d:/classpath/junit.jar"/>
>    </target>
>    <target name="test" depends="compile">
>      <junit fork="yes" printsummary="on">
>        <test name="MainTest"/>
>      </junit>
>    </target>
>    <target name="dist" depends="test">
>      <mkdir dir="${dist}/lib"/>
>      <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar"
basedir="${build}"/>
>    </target>
>    <target name="clean">
>      <delete dir="${build}"/>
>      <delete dir="${dist}"/>
>    </target>
> </project>
>
>
>
> >----- Original Message -----
> >From: "Ray Tayek" <rtayek@mediaone.net>
> >To: "Ant Users List" <ant-user@jakarta.apache.org>
> >Sent: Sunday, January 06, 2002 7:33 PM
> >Subject: Re: simple ant and junit fails
> >
> >
> > > At 01:57 PM 1/6/02 -0500, you wrote:
> > > >Two possible classic issues:
> > > >
> > > >- Did you download the "optional" Ant JAR file that contains the
<junit>
> > > >task itself?
> > >
> > > nope, duh! that's probably the problem. trying now, (i put the
optional
> >jar
> > > where you said) but it still says the same thing:
> > >
> > > D:\usr\ray\java\junit>ant
> > > "C:\jdk1.3.1_01\bin\java" -classpath
> > >
>
>"C:\jdk1.3.1_01\lib\tools.jar;D:\ant\lib\JAKART~1.JAR;D:\ant\lib\JAXP.JAR;D
:
> >\ant\lib\CRIMSON.JAR;D:\ant\lib\ANT.JAR;d:\classpath"
> > > -Dant.home="D:\ant"  org.apache.tools.ant.Main
> > > Buildfile: build.xml
> > >
> > > init:
> > >
> > > compile:
> > >
> > > test:
> > >
> > > BUILD FAILED
> > >
> > > D:\usr\ray\java\junit\build.xml:24: Could not create task of type:
junit.
> > > Common solutions are to use taskdef to declare your task, or, if this
is
> >an
> > > optional task, to put the optional.jar in the lib directory of your
ant
> > > installation (ANT_HOME).
> > >
> > > Total time: 0 seconds
> > >
> > > using this build.xml:
> > >
> > > <project name="MyProject" default="dist" basedir=".">
> > >
> > >    <!-- set global properties for this build -->
> > >    <property name="src" value="."/>
> > >    <property name="build" value="build"/>
> > >    <property name="dist"  value="dist"/>
> > >    <property name="test"  value="test"/>
> > >
> > >    <target name="init">
> > >      <tstamp/>
> > >      <mkdir dir="${build}"/>
> > >    </target>
> > >    <target name="compile" depends="init">
> > >      <javac srcdir="${src}" destdir="${build}"
> > > classpath=".;d:/classpath/junit.jar"/>
> > >    </target>
> > >
> > >    <target name="test" depends="compile">
> > > <!--
> > >          <classpath>
> > >        <pathelement path="${classpath}"/>
> > >        <pathelement location="junit.jar"/>
> > >      </classpath>
> > > -->
> > >      <junit fork="yes">
> > >        <test name="MainTest"/>
> > >      </junit>
> > >    </target>
> > >
> > >    <target name="dist" depends="test">
> > >      <mkdir dir="${dist}/lib"/>
> > >      <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar"
> >basedir="${build}"/>
> > >    </target>
> > >
> > >    <target name="clean">
> > >      <delete dir="${build}"/>
> > >      <delete dir="${dist}"/>
> > >    </target>
> > > </project>
> > >
> > > >- Do you have junit.jar in your Ant classpath?
> > >
> > > not sure how to do this. is the commented example correct? i got the
> > > junit.jar in the classpath on the compile step by using an attribute
of
> > > <javac...>, but anaict, there is no attribute for <junit...>.
> > >
> > > sorry to be so confused about this, but is not clear where all these
> > > different classpaths go :(
> > >
> > > thanks
> > >
> > > >----- Original Message -----
> > > >From: "Ray Tayek" <rtayek@mediaone.net>
> > > >To: "Ant Users List" <ant-user@jakarta.apache.org>
> > > >Sent: Sunday, January 06, 2002 1:39 PM
> > > >Subject: simple ant and junit fails
> > > >
> > > >
> > > > > hi, new to ant. tried to add a junit to the sample build.xml in
the
> >doc.
> > > > > getting the following when using the build.xml below. the junit
stuff
> > > >works
> > > > > ok if i run it by hand using java -cp .;d:/classpath/junit.jar;.
> >MainTest
> > > > >
> > > > >
> > > > > BUILD FAILED
> > > > > D:\usr\ray\java\junit\build.xml:22: Could not create task of type:
> >junit.
> > > > > Common solutions are to use taskdef to declare your task, or, if
this
> >is
> > > >an
> > > > > optional task, to put the optional.jar in the lib directory of
your
> >ant
> > > > > installation (ANT_HOME).
> > > > >
> > > > >
> > > > > D:\usr\ray\java\junit>ant
> > > > > "C:\jdk1.3.1_01\bin\java" -classpath
> > > > >
> > >
> >
>"C:\jdk1.3.1_01\lib\tools.jar;D:\ant\lib\JAXP.JAR;D:\ant\lib\CRIMSON.JAR;D:
> >\
> > > >ant\lib\ANT.JAR;d:\classpath"
> > > > >   -Dant.home="D:\ant"  org.apache.tools.ant.Main
> > > > > Buildfile: build.xml
> > > > > init:
> > > > > compile:
> > > > > test:
> > > > > BUILD FAILED
> > > > > D:\usr\ray\java\junit\build.xml:22: Could not create task of type:
> >junit.
> > > > > Common solutions are to use taskdef to declare your task, or, if
this
> >is
> > > >an
> > > > > optional task, to put the optional.jar in the lib directory of
your
> >ant
> > > > > installation (ANT_HOME).
> > > > >
> > > > > //build.xml:
> > > > > <project name="MyProject" default="dist" basedir=".">
> > > > >
> > > > >    <property name="src" value="."/>
> > > > >    <property name="build" value="build"/>
> > > > >    <property name="dist"  value="dist"/>
> > > > >    <property name="test"  value="test"/>
> > > > >
> > > > >    <target name="init">
> > > > >      <tstamp/>
> > > > >      <mkdir dir="${build}"/>
> > > > >    </target>
> > > > >    <target name="compile" depends="init">
> > > > >      <javac srcdir="${src}" destdir="${build}"
> > > > > classpath=".;d:/classpath/junit.jar"/>
> > > > >    </target>
> > > > >
> > > > >    <target name="dist" depends="test">
> > > > >      <mkdir dir="${dist}/lib"/>
> > > > >      <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar"
> > > >basedir="${build}"/>
> > > > >    </target>
> > > > >
> > > > >    <target name="test" depends="compile">
> > > > >      <junit fork="yes">
> > > > >        <test name="MainTest" />
> > > > >      </junit>
> > > > >    </target>
> > > > >
> > > > >    <target name="clean">
> > > > >      <delete dir="${build}"/>
> > > > >      <delete dir="${dist}"/>
> > > > >    </target>
> > > > > </project>
> > > > >
> > > > > //Main.java:
> > > > > import java.util.*;
> > > > > class Main
> > > > >          {
> > > > >          public void run(String[] argument) {
> > > > > System.out.println(this.getClass().getName()+" started at "+new
> >Date()); }
> > > > >          public void main(String[] argument) { (new
> > > >Main()).run(argument); }
> > > > >          }
> > > > >
> > > > > //MainTest.java:
> > > > > import junit.framework.*;
> > > > > import junit.swingui.*;
> > > > > public class MainTest extends TestCase
> > > > >          {
> > > > >          public MainTest(String name)
> > > > >                  { super(name); }
> > > > >          public void test1()
> > > > >                  { assertNotNull(new Main()); }
> > > > >          public static Test suite()
> > > > >                  { return new TestSuite(MainTest.class); }
> > > > >          private void run_(String[] argument)
> > > > >                  {
> > > > >                  if(true)
> > > > >                          junit.textui.TestRunner.run(suite());
> > > > >                          else
> > > > >                          {
> > > > >                          String[] string={ getClass().getName() };
> > > > >                          junit.swingui.TestRunner.main(string);
> > > > >                          }
> > > > >                  }
> > > > >          public static void main(String[] argument)
> > > > >                  {
> > > > >                  (new MainTest("run_")).run_(argument);
> > > > >                  }
> > > > >          }
> > > > >
> > > > > ---
> > > > > ray tayek http://home.earthlink.net/~rtayek/
> > > > > orange county java users group http://www.ocjug.org/
> > > > > want privacy? http://www.freedom.net/
> > > > > hate spam? http://samspade.org/ssw/
> > > > >
> > > > >
> > > > > --
> > > > > To unsubscribe, e-mail:
> ><mailto:ant-user-unsubscribe@jakarta.apache.org>
> > > > > For additional commands, e-mail:
> ><mailto:ant-user-help@jakarta.apache.org>
> > > > >
> > > > >
> > > >
> > > >
> > > >--
> > > >To unsubscribe, e-mail:
> ><mailto:ant-user-unsubscribe@jakarta.apache.org>
> > > >For additional commands, e-mail:
> ><mailto:ant-user-help@jakarta.apache.org>
> > >
> > > ---
> > > ray tayek http://home.earthlink.net/~rtayek/
> > > orange county java users group http://www.ocjug.org/
> > > want privacy? http://www.freedom.net/
> > > hate spam? http://samspade.org/ssw/
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
<mailto:ant-user-unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail:
<mailto:ant-user-help@jakarta.apache.org>
> > >
> > >
> >
> >
> >--
> >To unsubscribe, e-mail:
<mailto:ant-user-unsubscribe@jakarta.apache.org>
> >For additional commands, e-mail:
<mailto:ant-user-help@jakarta.apache.org>
>
> ---
> ray tayek http://home.earthlink.net/~rtayek/
> orange county java users group http://www.ocjug.org/
> want privacy? http://www.freedom.net/
> hate spam? http://samspade.org/ssw/
>
>
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
>
>



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


Mime
View raw message