2011-12-22 74 views
2

我有一个刚刚被导入到TFS的java项目,我一直试图让TFS输出单元测试的结果。TFS找不到来自Ant/JUnit构建单元测试结果

在TFSBuild.proj文件的最后,我有以下几点:

<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> 

这揭开序幕构建并告诉TFS在哪里可以找到JUnit测试结果。 问题是,尽管我可以看到测试运行的日志,但TFS并未找到单元测试结果。

回答

2

我几乎放弃了这一点,并更改了我的ant文件以生成junit报告并将其与构建工件一起存储。我改变了我的Ant任务是:

<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> 

但检查从未来建设的输出后,我意识到,JUnit的输出被保存为测试 - TestSuites.xml, TEST - * XML。我相应地更改了我的TFSBuild.proj文件,现在生成的结果显示在TFS中。

不知怎的,junitreport任务仍然收到输出。