Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant JUnit Batchtest .java or .class

Tags:

java

junit

ant

I have seen a few links which appears to imply that JUnit tests can be executed from the .java file instead of the .class

For example

<junit printsummary="yes" haltonfailure="yes" haltonerror="yes">
        <classpath refid="ui.tests.classpath"/>
        <formatter type="xml"/>
        <batchtest todir="${env.WORKSPACE}/UITests/output">
            <fileset dir="${ui.tests.classes}">
                <include name="**/*Test.java"/>
            </fileset>
        </batchtest>
</junit>

Instead of

<junit printsummary="yes" haltonfailure="yes" haltonerror="yes">
        <classpath refid="ui.tests.classpath"/>
        <formatter type="xml"/>
        <batchtest todir="${env.WORKSPACE}/UITests/output">
            <fileset dir="${ui.tests.classes}">
                <include name="**/*Test.class"/>
            </fileset>
        </batchtest>
    </junit>

Is the first example a valid case? I could not get it working due to ClassNotFoundExceptions

like image 712
IanWatson Avatar asked Mar 25 '14 16:03

IanWatson


People also ask

What is ant in Junit?

This task is used to run tests from the JUnit testing framework. This task is depend on external libraries that are not included in Apache Ant distribution by default. The junit. jar and ant.

Is ant integrated with Junit?

The use of Ant makes it straight forward through the JUnit task.

How do you skip test cases in ant build?

If your project's build file is constructed like that, then it's a matter of running ANT with the compile target and that will skip the tests. If it isn't built like that then there is no other way than to change the build file and separate the unit tests into it's own target that is not the default.


1 Answers

I agree with the comment above, that it looks like the tag allows for either .java or .class.

I did a small test and when I ran a test with this setup - where the dir=somefolder, then using <include name="**/*Test.java"/> when the folder pointed at contains class files, then Ant will basically have an empty fileset to process for *Test.java, but when using <include name="**/*Test.class"/> then the fileset was not empty and the test cases will get run.

This was the result of my quick test. As far as I could tell, it looks like you need to specify the *Test.class to pickup the test cases.

like image 193
mikemil Avatar answered Oct 18 '22 03:10

mikemil