2017-08-10 73 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