Pickles 所產出的報表用來溝通,個人認為比 SpecRun 來的友善、清楚,SpecRun 的報表比較偏向開發,有在使用 SpecFlow 或是 cucumber/gherkin 語言開發的夥伴,你也可以試試看
開發環境:
- VS 2015 Update 2
- SpecFlow 2.0
- SpecRun 1.3
安裝 Pickles:
安裝方式有很多種,請參考:http://docs.picklesdoc.com/en/latest/GettingStarted/
Package Download:
https://github.com/picklesdoc/pickles/releases
From Nuget:
.NET 的開發人員,可以直接選擇 Nuget,如下圖:
對應到 Nuget 上的項目,有一點不太一樣,Pickles 指的是 Powershell,如下圖:
接下來的範例會使用 VS Package Manage Console 演練
Pickles 參數:
- Feature Directory: 必填,Feature 檔的路徑,他會遞迴搜尋子目錄,也會根據目錄結構,長出 Tree View 的節點
- Output Directory: 必填, 報表產出路徑
- Documentation Format:支援以下格式,個人偏好 dhtml
- HTML
- Dhtml
- Word (OpenXML)
- JSON
- Excel
- System Under Test Name:名稱
- System Under Test Version:版本
- Test Results Format:支援以下測試框架
- nunit
- nunit3,
- xunit
- xunit2
- mstest
- cucumberjson
- specrun
- vstest
- Test Results File:測試結果路徑
- Language: 可以為 cucumber/gherkin 定義本地化語言,沒在用本地化語言,沒用過
- Include Experimental Features:包含實驗性功能,2.5 新功能,沒用過
範例:
Pickles.Powershell
使用 Package Manager Console,在目前專案產生報表,如下圖:
$FeatureDirectory=Split-Path (Get-Project).FileName
$OutputDirectory=$FeatureDirectory+"\bin\pickles"
if((Test-Path -Path $OutputDirectory)){Remove-Item -recurse $OutputDirectory}
Pickle-Features -FeatureDirectory $FeatureDirectory -OutputDirectory $OutputDirectory -DocumentationFormat dhtml
參考:http://docs.picklesdoc.com/en/latest/PowerShellcommandlet/
Pickles.MSBuild
在你的 .csproj 檔案加入以下,執行 Build(建置) 的時候就會觸發應用程式,然後產生報表
<PropertyGroup>
<Pickles_Generate>True</Pickles_Generate>
<Pickles_FeatureDirectory>$(MSBuildProjectDirectory)</Pickles_FeatureDirectory>
<Pickles_DocumentationFormat>dhtml</Pickles_DocumentationFormat>
<Pickles_OutputDirectory>$(MSBuildProjectDirectory)\bin\pickles</Pickles_OutputDirectory>
</PropertyGroup>
參考:http://docs.picklesdoc.com/en/latest/MSBuildTask/
長出來的報表樣式就跟下圖一樣,下圖出自:http://www.picklesdoc.com/Output/Dhtml/Index.html#Features\05TablesAndAssist\TableScenario.feature
整合測試結果
Pickles 並不會直接產生測試結果,這裡必須要用到 MsTest 來產生結果,再把結果餵給 Pickles,MsTest 需要 *Test*.dll,所以要先 Build 過,在加上以下程式碼,有關 MsTest 可參考:https://msdn.microsoft.com/zh-tw/library/ms182489.aspx
$fs = New-Object -ComObject Scripting.FileSystemObject
$f = $fs.GetFile("C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe")
$MsTestPath = $f.shortpath
$ProjectFolder=Split-Path (Get-Project).FileName
$TestResultFolder=$ProjectFolder + '\bin\Debug\TestResults'
$TestDll=$ProjectFolder + "\bin\Debug\"+(Get-Project).Name+".dll"
$TestResultFile=$TestResultFolder + '\TestResult.trx'
$Arguments = " /testcontainer:" + '$TestDll' + " /resultsfile:" + '$TestResultFile'
# Pickles
$FeatureFolder=$ProjectFolder
$OutputFolder=$TestResultFolder+'\pickles'
if((Test-Path -Path $TestResultFolder)){Remove-Item -recurse $TestResultFolder}
New-Item $TestResultFolder -type directory
Invoke-Expression "$MsTestPath $Arguments"
Pickle-Features -FeatureDirectory $FeatureFolder -OutputDirectory $OutputFolder -DocumentationFormat dhtml -TestResultsFile $TestResultFile -TestResultsFormat mstest
執行結果如下圖:
整合測試結果的報表,會多一個綠色勾勾,如下圖:
若有謬誤,煩請告知,新手發帖請多包涵
Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET