public void Parse_ParsesAllParseableInputs_WithoutConsoleOutput(string testCaseName, string expectedNamespace, string expectedType, string expectedMethod) { using (var sw = new StringWriter()) { Console.SetOut(sw); var actual = new LegacyTestCaseNameParser().Parse(testCaseName); Assert.AreEqual(expectedNamespace, actual.Namespace); Assert.AreEqual(expectedType, actual.Type); Assert.AreEqual(expectedMethod, actual.Method); Assert.AreEqual(0, sw.ToString().Length); } }
public void Parse_ParsesAllParseableInputsWithoutNamespace_WithConsoleOutput(string testCaseName, string expectedNamespace, string expectedType, string expectedMethod) { using var sw = new StringWriter(); Console.SetOut(sw); var actual = new LegacyTestCaseNameParser().Parse(testCaseName); Assert.AreEqual(expectedNamespace, actual.Namespace); Assert.AreEqual(expectedType, actual.Type); Assert.AreEqual(expectedMethod, actual.Method); // Remove the trailing new line before comparing. Assert.AreEqual(LegacyTestCaseNameParser.TestCaseParserError, sw.ToString().Replace(sw.NewLine, string.Empty)); }
public void Parse_FailsGracefullyOnNonParseableInputs_WithConsoleOutput(string testCaseName) { using var sw = new StringWriter(); Console.SetOut(sw); var actual = new LegacyTestCaseNameParser().Parse(testCaseName); Assert.AreEqual(LegacyTestCaseNameParser.TestCaseParserUnknownNamespace, actual.Namespace); Assert.AreEqual(LegacyTestCaseNameParser.TestCaseParserUnknownType, actual.Type); Assert.AreEqual(testCaseName, actual.Method); // Remove the trailing new line before comparing. Assert.AreEqual(LegacyTestCaseNameParser.TestCaseParserError, sw.ToString().Replace(sw.NewLine, string.Empty)); }
public void MethodFormat_Class_ShouldIncludeClass() { DotnetTestFixture.Execute("method-class-test-results.xml;MethodFormat=Class"); string resultsFile = Path.Combine(DotnetTestFixture.RootDirectory, "method-class-test-results.xml"); XDocument resultsXml = XDocument.Load(resultsFile); var testcases = resultsXml.XPathSelectElements("/testsuites/testsuite") .Descendants() .Where(x => x.Name.LocalName == "testcase") .ToList(); foreach (var testcase in testcases) { // Note the new parser can't handle the names with just class.method var parsedName = new LegacyTestCaseNameParser().Parse(testcase.Attribute("name").Value); // If the name is parsable into two pieces, then we have a two piece name and // consider that to be a passing result. Assert.AreNotEqual(parsedName.Type, TestCaseNameParser.TestCaseParserUnknownType); } Assert.IsTrue(new JunitXmlValidator().IsValid(resultsXml)); }