-
Notifications
You must be signed in to change notification settings - Fork 325
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
Trx logger class name fix - NUnit data driven tests #1677
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5bb966a
Trx logger class name fix
abhishkk a859ed6
Merge branch 'master' into trxLoggerClassNameFix
abhishkk 72d3b9c
review comments
abhishkk 4f84322
Merge branch 'master' into trxLoggerClassNameFix
abhishkk 391ffbf
Method Comments
abhishkk 8963d2a
Merge branch 'master' into trxLoggerClassNameFix
abhishkk 7e34bd9
UTs fix
abhishkk 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,18 @@ | |
|
||
namespace Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests.Utility | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml; | ||
using Microsoft.TestPlatform.Extensions.TrxLogger.Utility; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using ObjectModel; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using ObjectModel = Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using TestOutcome = VisualStudio.TestPlatform.ObjectModel.TestOutcome; | ||
using TrxLoggerConstants = Microsoft.TestPlatform.Extensions.TrxLogger.Utility.Constants; | ||
using TrxLoggerOutcome = Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel.TestOutcome; | ||
using UriDataAttachment = VisualStudio.TestPlatform.ObjectModel.UriDataAttachment; | ||
|
||
|
@@ -60,6 +64,80 @@ public void ToCollectionEntriesShouldRenameAttachmentUriIfTheAttachmentNameIsSam | |
Directory.Delete(tempDir, true); | ||
} | ||
|
||
/// <summary> | ||
/// Unit test for assigning or populating test categories read to the unit test element. | ||
/// </summary> | ||
[TestMethod] | ||
public void ToTestElementShouldAssignTestCategoryOfUnitTestElement() | ||
{ | ||
ObjectModel.TestCase testCase = CreateTestCase("TestCase1"); | ||
ObjectModel.TestResult result = new ObjectModel.TestResult(testCase); | ||
TestProperty testProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "String array property", string.Empty, string.Empty, typeof(string[]), null, TestPropertyAttributes.Hidden, typeof(TestObject)); | ||
|
||
testCase.SetPropertyValue(testProperty, new[] { "AsmLevel", "ClassLevel", "MethodLevel" }); | ||
|
||
var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); | ||
|
||
object[] expected = new[] { "MethodLevel", "ClassLevel", "AsmLevel" }; | ||
|
||
CollectionAssert.AreEqual(expected, unitTestElement.TestCategories.ToArray().OrderByDescending(x => x.ToString()).ToArray()); | ||
} | ||
|
||
/// <summary> | ||
/// Unit test for regression when there's no test categories. | ||
/// </summary> | ||
[TestMethod] | ||
public void ToTestElementShouldNotFailWhenThereIsNoTestCategoreis() | ||
{ | ||
ObjectModel.TestCase testCase = CreateTestCase("TestCase1"); | ||
ObjectModel.TestResult result = new ObjectModel.TestResult(testCase); | ||
|
||
var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); | ||
|
||
object[] expected = Enumerable.Empty<Object>().ToArray(); | ||
|
||
CollectionAssert.AreEqual(expected, unitTestElement.TestCategories.ToArray()); | ||
} | ||
|
||
[TestMethod] | ||
public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnEndsWithTestName() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DRY; use datarow here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed dry |
||
{ | ||
var expectedClassName = "TestProject1.Class1"; | ||
var fullyQualifiedName = expectedClassName + "." + "TestMethod1(2, 3, 4.0d)"; | ||
var testName = "TestMethod1(2, 3, 4.0d)"; | ||
|
||
ObjectModel.TestCase testCase = CreateTestCase(fullyQualifiedName); | ||
|
||
ObjectModel.TestResult result = new ObjectModel.TestResult(testCase); | ||
|
||
var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase) as UnitTestElement; | ||
|
||
Assert.AreEqual(expectedClassName, unitTestElement.TestMethod.ClassName); | ||
Assert.AreEqual(testName, unitTestElement.TestMethod.Name); | ||
} | ||
|
||
[TestMethod] | ||
public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnDoesNotEndsWithTestName() | ||
{ | ||
var expectedClassName = "TestProject1.Class1.TestMethod1(2, 3, 4"; | ||
var fullyQualifiedName = "TestProject1.Class1.TestMethod1(2, 3, 4.0d)"; | ||
var testName = "TestMethod1"; | ||
|
||
ObjectModel.TestCase testCase = CreateTestCase(fullyQualifiedName); | ||
|
||
ObjectModel.TestResult result = new ObjectModel.TestResult(testCase); | ||
|
||
var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase) as UnitTestElement; | ||
|
||
Assert.AreEqual(expectedClassName, unitTestElement.TestMethod.ClassName); | ||
Assert.AreEqual(testName, unitTestElement.TestMethod.Name); | ||
} | ||
|
||
private static TestCase CreateTestCase(string fullyQualifiedName) | ||
{ | ||
return new ObjectModel.TestCase(fullyQualifiedName, new Uri("some://uri"), "DummySourceFileName"); | ||
} | ||
|
||
private static void SetupForToCollectionEntries(out string tempDir, out List<AttachmentSet> attachmentSets, out TestRun testRun, | ||
out string testResultsDirectory) | ||
{ | ||
|
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.
Add logging here.