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

Fix splitting of test name from fully qualified name #2355

Merged
merged 2 commits into from
Mar 5, 2020
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 @@ -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)";
Copy link
Member Author

@nohwnd nohwnd Mar 4, 2020

Choose a reason for hiding this comment

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

@singhsarab I moved the test data to be more explicit, because the helper method ValidateTestMethodProperties was re- implementing the same code in the test and in the source, and both of them had the same bug. The current behavior is explicitly stating the same thing that it did before I refactored. It splits on the decimal point in 4.0d, which I assume is not correct. What would be the correct behavior here?

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