Catharz
Catharz

Reputation: 1165

TFS Can't Find Unit Test Results from Ant/JUnit build

I have a java project that has just been imported into TFS and I've been trying to get TFS to output the results of the unit tests.

At the end of the TFSBuild.proj file I have the following:

<ItemGroup>
  <!--  Ant Call Configuration.
        The build file called should be included in the workspace of the build definition.
  -->

  <AntBuildFile Include="$/PROJECT_NAME/Main/tfsbuild.xml">
    <Targets>build,test</Targets>
    <Properties>BinariesRoot=$(BinariesRoot);BuildDefinitionName=$(BuildDefinitionName);BuildDefinitionUri=$(BuildDefinitionUri);BuildDirectory=$(BuildDirectory);BuildNumber=$(BuildNumber);DropLocation=$(DropLocation);LogLocation=$(LogLocation);SourceGetVersion=$(SourceGetVersion);TestResultsRoot=$(TestResultsRoot);TeamProject=$(TeamProject);WorkspaceName=$(WorkspaceName);WorkspaceOwner=$(WorkspaceOwner)</Properties>
    <Lib></Lib>
  </AntBuildFile>

  <!-- JUnit XML Results files should be created using the XML formatter
       and be located in the following path
  -->
  <JUnitLogFiles Include="$(BinariesRoot)\**\TEST-*.xml" />
</ItemGroup>

This kicks off the build and tells TFS where to find the junit test results. The issue is, TFS is not finding the unit test results even though I can see through the logs that the tests were run.

Upvotes: 2

Views: 1914

Answers (1)

Catharz
Catharz

Reputation: 1165

I almost gave up on this, and changed my ant file to produce a junit report and store it with the build artifacts. I changed my ant task to be:

    <target name="test" depends="compile-tests">
    <echo>Running unit tests, output should be in ${junit.output}</echo>
    <junit printsummary="yes">
        <classpath>
            <pathelement path="${compile.classpath}" />
            <pathelement path="${lib.dir}/junit-4.0.jar" />
            <pathelement path="${build}" />
            <pathelement path="${dist-classes}" />
        </classpath>

        <formatter type="xml" />

        <batchtest fork="yes" todir="${junit.output}">
            <fileset dir="${src.test}">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>
    </junit>

    <mkdir dir="${DropLocation}/${BuildNumber}/test_results" />
    <junitreport todir="${junit.output}">
        <fileset dir="${junit.output}">
            <include name="TEST-*.xml" />
        </fileset>
        <report todir="${DropLocation}/${BuildNumber}/test_results" />
    </junitreport>
</target>

But after checking the output from the next build, I realised that the JUnit output was saved as TESTS-TestSuites.xml, not TEST-*.xml. I changed my TFSBuild.proj file accordingly, and now have the build results appearing in TFS.

Somehow the junitreport task still picks up the output though.

Upvotes: 2

Related Questions