I have code base in which the unit tests are written with Machine Specifications leveraging the nuget based test runner Machine.Specifications.Runner.VisualStudio, v2.10 to execute the tests. It works fine from the context of Visual Studio (2015 & 2017) and filtering by Trait works as expected. However, when using the Test Assemblies build step it does not seem to honor the category filter. Is there something special with how the TFS build agent runs the test adapter compared to visual studio?
Example Test
[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);
}
Build Log
...
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
...
Update 8/25 - added the requested screen shots and feedback
Test Explorer without filtering
Notice there are 16 total tests, the indicates ones starting with when hitting are integration tests which are not expected to run within the context of the build agent.
Test Explorer with filtering on Category
The total number of tests has decreased from 16 to 14. Since the test did not have the requested tag it was dropped from the test run.
Running vs2015 vstest.console.exe
As for running the test outside of visual studio, it would appear that the test runner is experiencing issues loading the test adapter on my dev machine, whereas the adapter runs fine in Visual Studio and on the build agent.
/TestCaseFilter
of ` vstest.console.exe`. You test code above did not include the corresponding category info. For more info about the Test Filter Criteria in VStest task please refer this blog: dotnetcatch.com/2016/03/11/… – PatrickLu-MSFTContinuousIntegration
in the test of test run via visual studio. More details please see my update answer. – PatrickLu-MSFT