-
Notifications
You must be signed in to change notification settings - Fork 269
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
Fix multiple results not returned with custom TestMethod and TestClass (#358) #363
Merged
jayaranigarg
merged 9 commits into
microsoft:master
from
bignoncedric:multipletestresultsbug
Mar 28, 2018
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f51024e
Fix Multiple results in VS2017 test runner (#336)
0b48abb
Fixed PR comments
d80a026
Added tests with data-driven tests
25bea17
Fixed build
a9f76bc
Merge branch 'master' into multipletestresultsbug
jayaranigarg fbee0f1
Merge branch 'master' into multipletestresultsbug
jayaranigarg b2af498
Merge remote-tracking branch 'upstream/master' into multipletestresul…
jayaranigarg 97bca2b
Merge branch 'multipletestresultsbug' of https://github.com/bignonced…
jayaranigarg 5374612
Merge branch 'master' into multipletestresultsbug
jayaranigarg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/E2ETests/Smoke.E2E.Tests/CustomTestExecutionExtensibilityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace MSTestAdapter.Smoke.E2ETests | ||
{ | ||
using Microsoft.MSTestV2.CLIAutomation; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class CustomTestExecutionExtensibilityTests : CLITestBase | ||
{ | ||
private const string TestAssembly = "FxExtensibilityTestProject.dll"; | ||
|
||
[TestMethod] | ||
public void ExecuteCustomTestExtensibilityTests() | ||
{ | ||
this.InvokeVsTestForExecution(new string[] { TestAssembly }); | ||
this.ValidatePassedTestsContain( | ||
"CustomTestMethod1 - Execution number 1", | ||
"CustomTestMethod1 - Execution number 2", | ||
"CustomTestMethod1 - Execution number 4", | ||
"CustomTestMethod1 - Execution number 5", | ||
"CustomTestClass1 - Execution number 1", | ||
"CustomTestClass1 - Execution number 2", | ||
"CustomTestClass1 - Execution number 4", | ||
"CustomTestClass1 - Execution number 5"); | ||
this.ValidateFailedTestsContain( | ||
TestAssembly, | ||
"CustomTestMethod1 - Execution number 3", | ||
"CustomTestClass1 - Execution number 3"); | ||
} | ||
|
||
[TestMethod] | ||
public void ExecuteCustomTestExtensibilityWithTestDataTests() | ||
{ | ||
this.InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "FullyQualifiedName~CustomTestExTests.CustomTestMethod2"); | ||
this.ValidatePassedTests( | ||
"CustomTestMethod2 (B)", | ||
"CustomTestMethod2 (B)", | ||
"CustomTestMethod2 (B)"); | ||
this.ValidateFailedTests( | ||
TestAssembly, | ||
"CustomTestMethod2 (A)", | ||
"CustomTestMethod2 (A)", | ||
"CustomTestMethod2 (A)", | ||
"CustomTestMethod2 (C)", | ||
"CustomTestMethod2 (C)", | ||
"CustomTestMethod2 (C)"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
test/E2ETests/TestAssets/FxExtensibilityTestProject/CustomTestExTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
namespace FxExtensibilityTestProject | ||
{ | ||
using System.Collections.Generic; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[IterativeTestClass(5)] | ||
public class CustomTestExTests | ||
{ | ||
private static int customTestMethod1ExecutionCount; | ||
[IterativeTestMethod(5)] | ||
public void CustomTestMethod1() | ||
{ | ||
customTestMethod1ExecutionCount++; | ||
Assert.AreNotEqual(3, customTestMethod1ExecutionCount); | ||
} | ||
|
||
[IterativeTestMethod(3)] | ||
[DataRow("A")] | ||
[DataRow("B")] | ||
[DataRow("C")] | ||
public void CustomTestMethod2(string value) | ||
{ | ||
Assert.AreEqual("B", value); | ||
} | ||
|
||
private static int customTestClass1ExecutionCount; | ||
[TestMethod] | ||
public void CustomTestClass1() | ||
{ | ||
customTestClass1ExecutionCount++; | ||
Assert.AreNotEqual(3, customTestClass1ExecutionCount); | ||
} | ||
} | ||
|
||
public class IterativeTestMethodAttribute : TestMethodAttribute | ||
{ | ||
private readonly int stabilityThreshold; | ||
|
||
public IterativeTestMethodAttribute(int stabilityThreshold) | ||
{ | ||
this.stabilityThreshold = stabilityThreshold; | ||
} | ||
|
||
public override TestResult[] Execute(ITestMethod testMethod) | ||
{ | ||
var results = new List<TestResult>(); | ||
for (int count = 0; count < this.stabilityThreshold; count++) | ||
{ | ||
var testResults = base.Execute(testMethod); | ||
foreach (var testResult in testResults) | ||
{ | ||
testResult.DisplayName = $"{testMethod.TestMethodName} - Execution number {count + 1}"; | ||
} | ||
results.AddRange(testResults); | ||
} | ||
|
||
return results.ToArray(); | ||
} | ||
} | ||
|
||
public class IterativeTestClassAttribute : TestClassAttribute | ||
{ | ||
private readonly int stabilityThreshold; | ||
|
||
public IterativeTestClassAttribute(int stabilityThreshold) | ||
{ | ||
this.stabilityThreshold = stabilityThreshold; | ||
} | ||
|
||
public override TestMethodAttribute GetTestMethodAttribute(TestMethodAttribute testMethodAttribute) | ||
{ | ||
if (testMethodAttribute is IterativeTestMethodAttribute) return testMethodAttribute; | ||
|
||
return new IterativeTestMethodAttribute(this.stabilityThreshold); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a data-driven test with [IterativeTestMethod] attribute