我有代碼庫,其中使用基於nuget的測試運行器Machine.Specifications.Runner.VisualStudio v2的機器規格編寫了單元測試。 10執行測試。它從Visual Studio(2015 & 2017)的上下文中正常工作,並按特性按預期進行過濾。但是,使用測試組件構建步驟時,似乎並未兌現類別過濾器。與Visual Studio相比,TFS構建代理如何運行測試適配器有什麼特別之處嗎?使用mspec測試適配器進行TFS 2015 vNext構建中的測試類別過濾器不進行過濾測試
實施例試驗
[Subject(typeof(RetrieveConfiguration))]
[Tags(Categories.Manual)]
public class When_hitting_the_general_services_uri : SpecificationContext
{
private static TestResult result;
Establish context =() =>
{
IServiceInfo serviceInfo = Substitute.For<IServiceInfo>();
serviceInfo.Url = "";
environment.GetService("Confiugration", "Retrieve").Returns(serviceInfo);
x509Manager.LoadFromSignature(ValidSignature).Returns(LoadFromMachine(ValidSignature));
};
Because of =() => error = Catch.Exception(() => result = sut.Execute(new Uri("https://myproductionuri/retrieve"), environment));
It should_have_the_succeeded =() => result.Result.ShouldEqual(StepResult.Success);
}
生成日誌
...
2017-08-10T20:49:44.8717852Z ##[debug]Calling Invoke-VSTest for all test assemblies
2017-08-10T20:49:44.9655216Z Working folder: E:\B39\BA78\WS\18
2017-08-10T20:49:44.9655216Z Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "E:\B39\BA78\WS\18\s\Src\Test\Verifier.Reporting.Azure.Storage.Spec\bin\Release\Verifier.Reporting.Azure.Store.Spec.dll" /TestCaseFilter:"TestCategory=ContinuousIntegration" /EnableCodeCoverage /logger:trx /TestAdapterPath:"E:\B39\BA78\WS\18\s"
2017-08-10T20:49:45.1999042Z Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1
2017-08-10T20:49:45.1999042Z Copyright (c) Microsoft Corporation. All rights reserved.
2017-08-10T20:49:45.5592884Z Starting test execution, please wait...
2017-08-10T20:49:56.8721150Z Information: Machine Specifications Visual Studio Test Adapter - Executing tests in E:\B39\BA78\WS\18\s\Src\Test\Verifier.Reporting.Azure.Storage.Spec\bin\Release\Verifier.Reporting.Azure.Store.Spec.dll
2017-08-10T20:50:01.5285749Z Passed Verifier.Reporting.Azure.Store.Spec.When_publishing_a_report.should_have_succeeded
...
更新8/25 - 添加請求的屏幕截圖和反饋
公告有16周總的測試,擊球是集成測試哪些不是當指示開始者預計將在構建代理的上下文中運行。
測試資源管理器與過濾測試的總數從16下降到14,因爲測試沒有要求的標籤就從試運行下降。
至於運行測試的Visual Studio之外,它會出現在測試運行遇到加載我的開發機器上的測試適配器的問題,而適配器在Visual Studio和構建代理上運行良好。
您能否在構建日誌中分享相關的錯誤消息? –
@ Patrick-MSFT我在單元測試的執行過程中添加了構建日誌的一部分。作爲構建的一部分沒有引發錯誤,只是執行未使用篩選器中應用的指定TestCategory \ Trait修飾的測試。測試不通過,因爲它們引用了構建代理主機根本不可用的資源。我們通過在測試周圍添加debug pragmas來解決問題,但這不是理想的解決方案。 – Tedford
當您使用本地VS過濾測試時,您傳遞了哪些參數? TFS VStest任務中的測試過濾條件與vstest.console.exe控制檯選項'/ TestCaseFilter'的工作方式相同。您上面的測試代碼不包含相應的類別信息。有關VStest任務中* Test Filter Criteria *的更多信息,請參閱以下博客:http://www.dotnetcatch.com/2016/03/11/vststfs-visual-studio-test-task-filter-criteria/ –