/// <summary> /// Makes a TestCase from an NUnit test, adding /// navigation data if it can be found. /// </summary> private TestCase MakeTestCaseFromXmlNode(XmlNode testNode) { var testCase = new TestCase( testNode.GetAttribute("fullname"), new Uri(NUnit3TestExecutor.ExecutorUri), _sourceAssembly) { DisplayName = testNode.GetAttribute("name"), CodeFilePath = null, LineNumber = 0 }; var className = testNode.GetAttribute("classname"); var methodName = testNode.GetAttribute("methodname"); var navData = _navigationDataProvider.GetNavigationData(className, methodName); if (navData.IsValid) { testCase.CodeFilePath = navData.FilePath; testCase.LineNumber = navData.LineNumber; } testCase.AddTraitsFromTestNode(testNode); return(testCase); }
/// <summary> /// Makes a TestCase from an NUnit test, adding /// navigation data if it can be found. /// </summary> private TestCase MakeTestCaseFromXmlNode(XmlNode testNode) { var testCase = new TestCase( testNode.GetAttribute("fullname"), new Uri(NUnitTestAdapter.ExecutorUri), _sourceAssembly) { DisplayName = testNode.GetAttribute("name"), CodeFilePath = null, LineNumber = 0 }; if (CollectSourceInformation && _navigationDataProvider != null) { var className = testNode.GetAttribute("classname"); var methodName = testNode.GetAttribute("methodname"); var navData = _navigationDataProvider.GetNavigationData(className, methodName); if (navData.IsValid) { testCase.CodeFilePath = navData.FilePath; testCase.LineNumber = navData.LineNumber; } } testCase.AddTraitsFromTestNode(testNode, TraitsCache, _logger, adapterSettings); return(testCase); }
/// <summary> /// Makes a TestCase from an NUnit test, adding /// navigation data if it can be found. /// </summary> private TestCase MakeTestCaseFromXmlNode(XmlNode testNode) { var fullyQualifiedName = testNode.GetAttribute("fullname"); var parentType = testNode.ParentNode.GetAttribute("type"); if (parentType == "ParameterizedMethod") { var parameterizedTestFullName = testNode.ParentNode.GetAttribute("fullname"); // VS expected FullyQualifiedName to be the actual class+type name,optionally with parameter types // in parenthesis, but they must fit the pattern of a value returned by object.GetType(). // It should _not_ include custom name or param values (just their types). // However, the "fullname" from NUnit's file generation is the custom name of the test, so // this code must convert from one to the other. // Reference: https://github.com/microsoft/vstest-docs/blob/master/RFCs/0017-Managed-TestCase-Properties.md // Using the nUnit-provided "fullname" will cause failures at test execution time due to // the FilterExpressionWrapper not being able to parse the test names passed-in as filters. // To resolve this issue, for parameterized tests (which are the only tests that allow custom names), // the parent node's "fullname" value is used instead. This is the name of the actual test method // and will allow the filtering to work as expected. if (!string.IsNullOrEmpty(parameterizedTestFullName)) { fullyQualifiedName = parameterizedTestFullName; } } var id = testNode.GetAttribute("id"); var testCase = new TestCase( fullyQualifiedName, new Uri(NUnitTestAdapter.ExecutorUri), _sourceAssembly) { DisplayName = testNode.GetAttribute("name"), CodeFilePath = null, LineNumber = 0, Id = EqtHash.GuidFromString(id) }; if (CollectSourceInformation && _navigationDataProvider != null) { var className = testNode.GetAttribute("classname"); var methodName = testNode.GetAttribute("methodname"); var navData = _navigationDataProvider.GetNavigationData(className, methodName); if (navData.IsValid) { testCase.CodeFilePath = navData.FilePath; testCase.LineNumber = navData.LineNumber; } } testCase.AddTraitsFromTestNode(testNode, TraitsCache, _logger, adapterSettings); return(testCase); }
/// <summary> /// Makes a TestCase from an NUnit test, adding /// navigation data if it can be found. /// </summary> private TestCase MakeTestCaseFromDiscoveryNode(NUnitDiscoveryTestCase testNode) { string fullyQualifiedName = testNode.FullName; if (adapterSettings.UseParentFQNForParametrizedTests) { var parent = testNode.Parent; if (parent != null && parent.IsParameterizedMethod) { var parameterizedTestFullName = parent.FullName; // VS expected FullyQualifiedName to be the actual class+type name,optionally with parameter types // in parenthesis, but they must fit the pattern of a value returned by object.GetType(). // It should _not_ include custom name or param values (just their types). // However, the "fullname" from NUnit's file generation is the custom name of the test, so // this code must convert from one to the other. // Reference: https://github.com/microsoft/vstest-docs/blob/master/RFCs/0017-Managed-TestCase-Properties.md // Using the nUnit-provided "fullname" will cause failures at test execution time due to // the FilterExpressionWrapper not being able to parse the test names passed-in as filters. // To resolve this issue, for parameterized tests (which are the only tests that allow custom names), // the parent node's "fullname" value is used instead. This is the name of the actual test method // and will allow the filtering to work as expected. // Note that this also means you can no longer select a single tests of these to run. // When you do that, all tests within the parent node will be executed if (!string.IsNullOrEmpty(parameterizedTestFullName)) { fullyQualifiedName = parameterizedTestFullName; } } } var testCase = new TestCase( fullyQualifiedName, new Uri(NUnitTestAdapter.ExecutorUri), _sourceAssembly) { DisplayName = CreateDisplayName(fullyQualifiedName, testNode.Name), CodeFilePath = null, LineNumber = 0 }; if (adapterSettings.UseNUnitIdforTestCaseId) { testCase.Id = EqtHash.GuidFromString(testNode.Id); } if (CollectSourceInformation && _navigationDataProvider != null) { if (!CheckCodeFilePathOverride()) { var navData = _navigationDataProvider.GetNavigationData(testNode.ClassName, testNode.MethodName); if (navData.IsValid) { testCase.CodeFilePath = navData.FilePath; testCase.LineNumber = navData.LineNumber; } } } else { _ = CheckCodeFilePathOverride(); } testCase.AddTraitsFromTestNode(testNode, TraitsCache, _logger, adapterSettings); return(testCase); bool CheckCodeFilePathOverride() { var codeFilePath = testNode.Properties.FirstOrDefault(p => p.Name == "_CodeFilePath"); if (codeFilePath == null) { return(false); } testCase.CodeFilePath = codeFilePath.Value; var lineNumber = testNode.Properties.FirstOrDefault(p => p.Name == "_LineNumber"); testCase.LineNumber = lineNumber != null?Convert.ToInt32(lineNumber.Value) : 1; return(true); } }
/// <summary> /// Makes a TestCase from an NUnit test, adding /// navigation data if it can be found. /// </summary> private TestCase MakeTestCaseFromXmlNode(XmlNode testNode) { var testCase = new TestCase( testNode.GetAttribute("fullname"), new Uri(NUnit3TestExecutor.ExecutorUri), this.sourceAssembly) { DisplayName = testNode.GetAttribute("name"), CodeFilePath = null, LineNumber = 0 }; var className = testNode.GetAttribute("classname"); var methodName = testNode.GetAttribute("methodname"); var navData = GetNavigationData(className, methodName); if (navData != null) { testCase.CodeFilePath = navData.FileName; testCase.LineNumber = navData.MinLineNumber; } testCase.AddTraitsFromTestNode(testNode); return testCase; }