Skip to content

Commit

Permalink
Fix splitting of test name from fully qualified name (#2355)
Browse files Browse the repository at this point in the history
* Fix splitting of test name from fully qualified name

* Remove the same implementation in tests
  • Loading branch information
nohwnd authored Mar 5, 2020
1 parent 5752756 commit 53da99a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ private TestElement CreateTestElement(Guid testId, string name, string fullyQual
{
var codeBase = source;
var className = GetTestClassName(name, fullyQualifiedName, source);
var testMethodName = fullyQualifiedName.StartsWith(className) ? fullyQualifiedName.Remove(0, $"{className}.".Length) : fullyQualifiedName;
var testMethodName = fullyQualifiedName.StartsWith($"{className}.") ? fullyQualifiedName.Remove(0, $"{className}.".Length) : fullyQualifiedName;
var testMethod = new TestMethod(testMethodName, className);

testElement = new UnitTestElement(testId, name, adapter, testMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,33 @@ public void ToTestElementShouldNotFailWhenThereIsNoTestCategoreis()
public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnIsSameAsTestName()
{
var expectedClassName = "TestProject1.Class1";
var fullyQualifiedName = expectedClassName + "." + "TestMethod1";
var expectedTestName = "TestMethod1";
var fullyQualifiedName = expectedClassName + "." + expectedTestName;
var testName = "TestProject1.Class1.TestMethod1";

ValidateTestMethodProperties(testName, fullyQualifiedName, expectedClassName);
ValidateTestMethodProperties(testName, fullyQualifiedName, expectedClassName, expectedTestName);
}

[TestMethod]
public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnEndsWithTestName()
{
var expectedClassName = "TestProject1.Class1";
var fullyQualifiedName = expectedClassName + "." + "TestMethod1(2, 3, 4.0d)";
var expectedTestName = "TestMethod1(2, 3, 4.0d)";
var fullyQualifiedName = expectedClassName + "." + expectedTestName;
var testName = "TestMethod1(2, 3, 4.0d)";

ValidateTestMethodProperties(testName, fullyQualifiedName, expectedClassName);
ValidateTestMethodProperties(testName, fullyQualifiedName, expectedClassName, expectedTestName);
}

[TestMethod]
public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnDoesNotEndsWithTestName()
{
var expectedClassName = "TestProject1.Class1.TestMethod1(2, 3, 4";
var fullyQualifiedName = "TestProject1.Class1.TestMethod1(2, 3, 4.0d)";
var expectedTestName = "0d)";
var fullyQualifiedName = "TestProject1.Class1.TestMethod1(2, 3, 4." + expectedTestName;
var testName = "TestMethod1";

ValidateTestMethodProperties(testName, fullyQualifiedName, expectedClassName);
ValidateTestMethodProperties(testName, fullyQualifiedName, expectedClassName, expectedTestName);
}

[TestMethod]
Expand All @@ -161,13 +164,32 @@ public void ToResultFilesShouldAddAttachementsWithRelativeURI()
Assert.IsTrue(resultFiles[0].Contains("abc.txt"));
}

private void ValidateTestMethodProperties(string testName, string fullyQualifiedName, string expectedClassName)
[TestMethod]
public void ToTestElementShouldNotFailWhenClassNameIsTheSameAsFullyQualifiedName()
{
// the converter assumed to find 'classname' in the fqn and split it on 'classname.'
// but that threw an exception because 'classname.' is not contained in 'classname'
// (notice the . at the end)
// we should not be assuming that the fqn will have '.' in them
// seen it for example with qtest

string expectedClassName, expectedTestName, fullyQualifiedName, source, testName;
expectedClassName = expectedTestName = fullyQualifiedName = source = testName = "test1";

TestPlatformObjectModel.TestCase testCase = new TestPlatformObjectModel.TestCase(fullyQualifiedName, new Uri("some://uri"), source);
TestPlatformObjectModel.TestResult result = new TestPlatformObjectModel.TestResult(testCase);
var unitTestElement = this.converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase) as UnitTestElement;

Assert.AreEqual(expectedClassName, unitTestElement.TestMethod.ClassName);
Assert.AreEqual(expectedTestName, unitTestElement.TestMethod.Name);
}

private void ValidateTestMethodProperties(string testName, string fullyQualifiedName, string expectedClassName, string expectedTestName)
{
TestPlatformObjectModel.TestCase testCase = CreateTestCase(fullyQualifiedName);
TestPlatformObjectModel.TestResult result = new TestPlatformObjectModel.TestResult(testCase);

var unitTestElement = this.converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase) as UnitTestElement;
var expectedTestName = fullyQualifiedName.StartsWith(expectedClassName) ? fullyQualifiedName.Remove(0, $"{expectedClassName}.".Length) : fullyQualifiedName;

Assert.AreEqual(expectedClassName, unitTestElement.TestMethod.ClassName);
Assert.AreEqual(expectedTestName, unitTestElement.TestMethod.Name);
Expand Down

0 comments on commit 53da99a

Please sign in to comment.