2010-12-15 74 views
1

這是我第一次設置teamcity,我遇到了一些顯示結果的問題。我想要一個運行NAnt腳本的構建步驟。腳本應該通過PartCover運行我的單元測試並顯示結果。結果應該是:如何設置TeamCity/NAnt/Gallio/PartCover來顯示測試結果?

  • 測試,傳遞失敗
  • 覆蓋率報告

/測試,但我真的不知道如何設置的腳本或設置,甚至我應該在哪裏查看這些結果(我猜測的工件部分?)。使用下面的腳本,一切運行正常,但我無法查看任何報告。

<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 

<loadtasks assembly="C:\Program Files\Gallio\bin\Gallio.NAntTasks.dll" /> 

<target name="test"> 
    <gallio result-property="exitCode" failonerror="false" > 
    <runner-extension value="TeamCityExtension,Gallio.TeamCityIntegration" /> 
    <files> 
     <include name="%system.teamcity.build.checkoutDir%\Trunk\MyLibrary.Testing\bin\Release\MyLibrary.Testing.dll"/> 
    </files> 
    </gallio> 
    <fail if="${exitCode != '0'}" >One or more tests failed. Please check the log for more details</fail>  
</target> 

</project> 

對於.NET覆蓋部分,我有PartCover(2.2或2.3)選擇,但我沒有在PartCover任何參數(要這樣呢?)

感謝您的幫助!

回答

0

我遇到了NAnt的問題,並決定使用MSBuild。 MSBuild更容易使用,並給出了非常具有描述性的錯誤消息。 (我也發現我們的NCover許可證也是這樣使用的)。這是我感興趣的任何人的腳本。我從網上的不同位置找到它的代碼。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 

    <PropertyGroup> 
    <CoverageDir>.\Tests\Output\Coverage</CoverageDir> 
    <CoverageFilesDir>.\Tests\Output\Coverage\files</CoverageFilesDir> 
    <BinDir>Testing\bin\x86\Release</BinDir> 
    <NCoverDir>C:\Program Files (x86)\NCover</NCoverDir> 
    <GallioDir>C:\Program Files (x86)\Gallio\bin</GallioDir> 
    </PropertyGroup> 

    <UsingTask TaskName="NCover" AssemblyFile="$(NCoverDir)\Build Task Plugins\NCover.MSBuildTasks.dll" /> 
    <UsingTask TaskName="NCoverExplorer" AssemblyFile="$(NCoverDir)\Build Task Plugins\NCoverExplorer.MSBuildTasks.dll"/> 

    <!-- Specify the tests assemblies --> 
    <ItemGroup> 
    <TestAssemblies Include="$(BinDir)\library.Testing.dll" /> 
    <CoverageAssemblies Include="$(BinDir)\library.dll" /> 
    </ItemGroup> 

    <Target Name="Coverage"> 
     <Message Text="Creating $(CoverageFilesDir)" /> 
     <MakeDir Directories="$(CoverageFilesDir)"/> 

     <Message Text="##-------------------- Running Coverage Reports --------------------##" /> 
     <Message Text="Coverage Assemblies @(TestAssemblies)" /> 

     <!--Run NCover to gather coverage information--> 
     <NCover 
     ToolPath="$(NCoverDir)" 
     TestRunnerExe="$(GallioDir)\Gallio.Echo.exe" 
     TestRunnerArgs="%(TestAssemblies.FullPath)" 
     IncludeAssemblies="@(CoverageAssemblies)" 
     LogFile="$(CoverageFilesDir)\%(TestAssemblies.Filename)-ncover.log" 
     RegisterProfiler="false" 
     CoverageFile="$(CoverageFilesDir)\%(TestAssemblies.Filename)-coverage.xml"/>  

     <CreateItem Include="$(CoverageFilesDir)\*-coverage.xml"> 
     <Output TaskParameter="Include" ItemName="CoverageReports"/> 
     </CreateItem> 

     <!--Generate coverage report--> 
     <NCoverExplorer 
     ToolPath="$(NCoverDir)" 
     ProjectName="Library Coverage" 
     ReportType="4" 
     Sort="CoveragePercentageAscending" 
     Filter="None" 
     OutputDir="$(CoverageDir)" 
     XmlReportName="CoverageReport.xml" 
     HtmlReportName="CoverageReport.html" 
     ShowExcluded="True" 
     SatisfactoryCoverage="15" 
     FailMinimum="False" 
     CoverageFiles="@(CoverageReports)"/> 

     <!-- In case one of the tests fails, make sure to stop TypeMock and unregister NCover. --> 
     <OnError ExecuteTargets="test-finally"/> 
    </Target> 

    <!-- Stopping unregistering NCover is a separate target because it has to happen --> 
    <!-- regardless of success or failure of the unit tests. Like the "finally" in a "try/finally" block. --> 
    <Target Name="test-finally"> 
    <Exec Command="regsvr32 /u /s &quot;$(NCoverDir)\CoverLib.dll&quot;" ContinueOnError="true"/> 
    </Target> 

</Project> 
0

根據我的經驗,您不應該直接運行Gallio。相反,您應該運行PartCover,並在其命令行參數中指定Gallio作爲目標。 你可以在這裏找到關於Nant + PartCover的一些建議: Integrating PartCover.NET with NAnt

相關問題