Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Category to Test Category mapping for ListFullyQualifiedTests #1369

Merged
merged 2 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private class TestCaseFilter
{
private static TestCaseFilterExpression filterExpression;
private const string TestCategory = "TestCategory";
private const string Category = "Category";
private const string Traits = "Traits";

public TestCaseFilter()
Expand Down Expand Up @@ -436,6 +437,13 @@ private static Dictionary<string, List<string>> GetTraitsInTraitDictionary(Dicti
}
}

//This is hack for NUnit,Xunit to understand test category -> This method is called only for NUnit/Xunit
if (!traitDictionary.ContainsKey(TestCategory) && traitDictionary.ContainsKey(Category))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we test TIA with this change

{
traitDictionary.TryGetValue(Category, out var categoryValue);
traitDictionary.Add(TestCategory, categoryValue);
}

return traitDictionary;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ public void ExecutorExecuteShouldOutputDiscoveredTestsAndReturnSuccess()
Assert.IsTrue(fileOutput.Contains("Test2"));
}

[TestMethod]
public void DiscoveryShouldFilterCategoryTestsAndReturnSuccess()
{
var mockDiscoveryRequest = new Mock<IDiscoveryRequest>();
var mockConsoleOutput = new Mock<IOutput>();

this.RunListFullyQualifiedTestArgumentProcessorWithTraits(mockDiscoveryRequest, mockConsoleOutput);

mockDiscoveryRequest.Verify(dr => dr.DiscoverAsync(), Times.Once);

var fileOutput = File.ReadAllLines(this.dummyFilePath);
Assert.IsTrue(fileOutput.Length == 1);
Assert.IsTrue(fileOutput.Contains("Test1"));
Assert.IsTrue(!fileOutput.Contains("Test2"));
}

[ExpectedException(typeof(CommandLineException))]
[TestMethod]
public void ExecutorExecuteShouldThrowWhenListFullyQualifiedTestsTargetPathIsEmpty()
Expand Down Expand Up @@ -268,6 +284,31 @@ public void ListFullyQualifiedTestsArgumentProcessorExecuteShouldInstrumentDisco
}
#endregion

private void RunListFullyQualifiedTestArgumentProcessorWithTraits(Mock<IDiscoveryRequest> mockDiscoveryRequest, Mock<IOutput> mockConsoleOutput, bool legitPath = true)
{
var mockTestPlatform = new Mock<ITestPlatform>();
var list = new List<TestCase>();

var t1 = new TestCase("Test1", new Uri("http://FooTestUri1"), "Source1");
t1.Traits.Add(new Trait("Category", "MyCat"));
list.Add(t1);

var t2 = new TestCase("Test2", new Uri("http://FooTestUri2"), "Source2");
t2.Traits.Add(new Trait("Category", "MyBat"));
list.Add(t2);

mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(list));
mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny<IRequestData>(), It.IsAny<DiscoveryCriteria>())).Returns(mockDiscoveryRequest.Object);

this.ResetAndAddSourceToCommandLineOptions(legitPath);
var cmdOptions = CommandLineOptions.Instance;
cmdOptions.TestCaseFilterValue = "TestCategory=MyCat";

var testRequestManager = new TestRequestManager(cmdOptions, mockTestPlatform.Object, TestLoggerManager.Instance, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask);

GetExecutor(testRequestManager, mockConsoleOutput.Object).Execute();
}

private void RunListFullyQualifiedTestArgumentProcessorExecuteWithMockSetup(Mock<IDiscoveryRequest> mockDiscoveryRequest, Mock<IOutput> mockConsoleOutput, bool legitPath = true)
{
var mockTestPlatform = new Mock<ITestPlatform>();
Expand Down