0

I am trying to run ANT script to execute a simple junit test case. Now I have a requirement.

  1. The executable file with my sample product will be in one location
  2. My junit test cases will be in another location
  3. Still I have to sync up and get the test case executed

Is there a way where I can ask my Junit to look another location for source.

1
  • How is this related to Maven? Apr 16, 2015 at 15:45

2 Answers 2

0

If your junit test cases live in another project then you will need to create a seperate build.xml for that project setup for unit tests. Make sure this new build.xml references your sample product JAR as a dependency.

0
0

Yes this is possible.

Compile your source files as usual:

<javac srcdir="../${srcDir}/src" destdir="dist/src">

Compile your test files, including the compiled source in your classpath:

<javac srcdir="../${testDir}/test" destdir="dist/test">
   <classpath location="dist/src"/>
</javac>

Then include both these in the JUnit classpath:

<path id="junit.path">
    <pathelement location="dist/src" />
    <pathelement location="dist/test" />
    <fileset file="../Libraries/junit*.jar" />
    <fileset file="../Libraries/ant-junit*.jar" />
    <fileset dir="externalLibraries">
        <include name="**/*.jar" />
    </fileset>          
</path>


<junit fork="yes" forkmode="once">
    <classpath refid="junit.path" />

    <batchtest fork="yes" todir="${dist}/testresults">
        <fileset dir="dist/test">
            <include name="**/*Test.class" />
        </fileset>
    </batchtest>            
</junit>

See also Ant documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.