TimStefanHauschildt
TimStefanHauschildt

Reputation: 594

Running JUnit Tests by Ant in Jenkins without access to Source-Files?

I would like to enable a customer to run JUnit-Tests with Ant with Jenkins. I don´t want to deploy the source files to the customers´ Jenkins.

If the customer had a running jenkins installation, and I gave him only our compiled Java-Classes, compiled Test-Classes and our ant Script, would the customer be able to execute the tests with jenkins without having access to the sources?

My ant-target looks like this

<target name="testWithoutCompile">      
    <junit fork="true" forkmode="perBatch" haltonerror="false" haltonfailure="false" showoutput="false" printsummary="true" clonevm="true">
        <classpath>
            <path refid="test.run.classpath" />
        </classpath>
        <formatter type="xml" />
        <batchtest todir="${report.test.dir}">
            <fileset dir="${build.test.dir}">
                <include name="**/*Test.class" />
            </fileset>
        </batchtest>
    </junit>
</target>

Upvotes: 1

Views: 911

Answers (1)

matt freake
matt freake

Reputation: 5090

Yes, it is possible, at least with Ant directly.

I have simple project locally (just src and classes sub-directories) where I can run a specific unit-test, just using the class file (I removed both the test-class sources and source of the classes being tested, beforehand)

<target name="test">
        <junit>
              <classpath refid="test.path" />
              <formatter type="brief" usefile="false" />
              <test name="TestHobbyHorse" />
        </junit>
</target>

[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.011 sec
[junit] 
[junit] Testcase: testNoise(TestHobbyHorse):    Caused an ERROR
[junit] expected:<[noSound]> but was:<[Neigh]>
[junit]     at TestHobbyHorse.testNoise(Unknown Source)
[junit] 

I haven't tested, but would assume you could expand it to run a variety of Test classes, as you've tried in your build.xml, and as Jenkins should just be running Ant I don't see why the prescence of Jenkins would affect it.

Upvotes: 1

Related Questions