Avatar of samblake
samblake
 asked on

JUnit HTML Report With Ant And IntelliJ IDEA

Hi,

I'm new to the whole Ant thing. In fact I'm new to JUnit too but I don't think that should be a problem. I'm wanted to created HTML reports with Ant as it is said here: http://junit.sourceforge.net/doc/faq/faq.htm#running_6

"   1.

      Ensure that Ant's optional.jar file is either in your CLASSPATH or exists in your $ANT_HOME/lib directory.
   2.

      Add an ANT property for the directory containing the HTML reports:
      <property name="test.reports" value="./reports" />
   3.

      Define the Ant task for running JUnit and generating reports:


<target name="test-html">
  <junit fork="yes" printsummary="no" haltonfailure="no">
    <batchtest fork="yes" todir="${test.reports}" >
      <fileset dir="${classes}">
        <include name="**/*Test.class" />
      </fileset>
    </batchtest>
    <formatter type="xml" />
    <classpath refid="test.classpath" />
  </junit>

  <junitreport todir="${test.reports}">
    <fileset dir="${test.reports}">
      <include name="TEST-*.xml" />
    </fileset>
    <report todir="${test.reports}" />
  </junitreport>
</target>

   4.

      Run the test:
      ant test-html"

I have added optional.jar from the IntelliJ IDEA\lib directory to the Additional Classpath List in the Build File Propertys. I have created a folder call "reports" in the same directory as the build.xml file and changed value="./reports" to value="reports".

I then copied in the code in step three. tot he build file and surrounded it by <project name="MyProject" default="test-html" basedir="."> and <\project> tags. This, however doesn't run (I am running it from the IntelliJ Ant Build thing). I have also added the tags:

<property name="src" value="src" />
<property name="lib" value="lib" />
<property name="classes" value="classes" />

Having never used Ant before I'm not sure what the problem is.  When I try to run this I get the error "Could not create class or type of type: junit" pointing to the "<junit fork="yes" printsummary="no" haltonfailure="no">" line.

If I add the target:

<target name="hello">
        <echo message="Hello"/>
</target>

that will run however.

Any help would be much appreciated. Thanks.

-Sam

JavaJava EE

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
CEHJ

Are the JUnit jars available to Ant?
ASKER CERTIFIED SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
samblake

ASKER
I've put the junit.jar from IntelliJ Idea\lib into the Additional Classpath List in the Build File Properties thing in IntelliJ. Still I get the same error.

Could it maybe something to do with my directory structure? I have:

project
project\classes
project\src
project\reports

In project I have build.xml.
In src I have Mp3.java and Mp3Test.java.
In classes I have the clesses from the .java files.
Reports is empty at the moment.

Oh and in ..\lib I have the jid3lib and junit.

Thanks.

-Sam
samblake

ASKER
It's alright, I've got it figured out now. It was half the junit classpath problem.
Your help has saved me hundreds of hours of internet surfing.
fblack61
CEHJ

8-)