2017-08-10 40 views
1

我有代碼庫,其中使用基於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); 
    } 

生成步驟配置 TFS vNext build test step

生成日誌

... 
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 - 添加請求的屏幕截圖和反饋

測試資源管理器不進行過濾 Viewing tests in VS Test Explorer without any filtering

公告有16周總的測試​​,擊球是集成測試哪些不是當指示開始者預計將在構建代理的上下文中運行。

上分類 Filtering test using category in VS Test Explorer

測試資源管理器與過濾測試的總數從16下降到14,因爲測試沒有要求的標籤就從試運行下降。

運行vs2015 vstest.console.exe Screen shot of running vstest.console.exe on dev machine

至於運行測試的Visual Studio之外,它會出現在測試運行遇到加載我的開發機器上的測試適配器的問題,而適配器在Visual Studio和構建代理上運行良好。

+0

您能否在構建日誌中分享相關的錯誤消息? –

+0

@ Patrick-MSFT我在單元測試的執行過程中添加了構建日誌的一部分。作爲構建的一部分沒有引發錯誤,只是執行未使用篩選器中應用的指定TestCategory \ Trait修飾的測試。測試不通過,因爲它們引用了構建代理主機根本不可用的資源。我們通過在測試周圍添加debug pragmas來解決問題,但這不是理想的解決方案。 – Tedford

+0

當您使用本地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/ –

回答

0

vstest任務只是使用vstest.console.exe來執行測試。 TFS VStest任務中的測試過濾標準與控制檯選項/TestCaseFiltervstest.console.exe的工作方式相同。

"TestCategory=ContinuousIntegration" 

通過以上,我沒有在你的代碼中看到這樣的TestCategory名,如果我們使用命令行(vstest.console.exe)運行測試,我們必須指定匹配的名字,這意味着至少我們在測試方法代碼 之上命名TestCategory屬性。E,我的測試方法代碼:

[TestCategory("nine"), TestMethod()] 
    public void TestMethod1() 
    { 
     Assert.AreEqual(1, 1); 
    } 

我需要使用下面的代碼在命令行中運行它:

Vstest.console.exe UnitTestvstsada.dll /TestCaseFilter:TestCategory=nine 

它會成功篩選測試,並會得到同樣的結果在TFS生成。

至於過濾器測試瀏覽器,沒有這樣的選項來過濾測試。只有一個配置持續集成,實際上不是一個過濾器。如果你不介意的話,請告訴我們你是如何使用過濾特質的​​:ContinuousIntegration通過Visual Studio進行測試運行的測試。

enter image description here

怕使用濾波器性狀:持續整合是不等同於TestCategory=ContinuousIntegration在TFS2015生成代理。

+0

我用測試資源管理器中所要求的過濾屏幕截圖更新了我的問題,並嘗試使用vstest.console.exe運行 – Tedford