private static XunitTest CreateMethodTest(XunitTypeInfoAdapter typeInfo, XunitMethodInfoAdapter methodInfo) { XunitTest methodTest = new XunitTest(methodInfo.Name, methodInfo.Target, typeInfo, methodInfo); methodTest.Kind = TestKinds.Test; methodTest.IsTestCase = true; // Add skip reason. if (XunitMethodUtility.IsSkip(methodInfo)) { string skipReason = XunitMethodUtility.GetSkipReason(methodInfo); if (skipReason != null) { methodTest.Metadata.SetValue(MetadataKeys.IgnoreReason, skipReason); } } // Add traits. if (XunitMethodUtility.HasTraits(methodInfo)) { XunitMethodUtility.GetTraits(methodInfo).ForEach((key, value) => methodTest.Metadata.Add(key ?? @"", value ?? @"")); } // Add XML documentation. string xmlDocumentation = methodInfo.Target.GetXmlDocumentation(); if (xmlDocumentation != null) { methodTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation); } return(methodTest); }
private static TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep, IProgressMonitor progressMonitor) { Test test = testCommand.Test; progressMonitor.SetStatus(test.Name); TestResult result; XunitTest xunitTest = test as XunitTest; if (xunitTest == null) { result = RunChildTests(testCommand, parentTestStep, progressMonitor); } else { result = RunTestFixture(testCommand, xunitTest.TypeInfo, parentTestStep); } progressMonitor.Worked(1); return(result); }
private static XunitTest CreateTypeTest(XunitTypeInfoAdapter typeInfo, ITestClassCommand testClassCommand) { XunitTest typeTest = new XunitTest(typeInfo.Target.Name, typeInfo.Target, typeInfo, null); typeTest.Kind = TestKinds.Fixture; foreach (XunitMethodInfoAdapter methodInfo in testClassCommand.EnumerateTestMethods()) { typeTest.AddChild(CreateMethodTest(typeInfo, methodInfo)); } // Add XML documentation. string xmlDocumentation = typeInfo.Target.GetXmlDocumentation(); if (xmlDocumentation != null) { typeTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation); } return(typeTest); }
private static TestResult RunTestClassCommandAndFinishStep(ITestCommand testCommand, ITestContext testContext, XunitTestClassCommand testClassCommand) { try { bool passed = true; // Run ClassStart behavior, if applicable. testContext.LifecyclePhase = LifecyclePhases.SetUp; Exception ex = testClassCommand.ClassStart(); // Run tests. if (ex == null) { List <MethodInfo> testMethods = new List <MethodInfo>(); List <ITestCommand> testCommands = new List <ITestCommand>(); foreach (ITestCommand child in testCommand.Children) { XunitTest test = child.Test as XunitTest; if (test != null) { testMethods.Add(test.MethodInfo.Target.Resolve(false)); testCommands.Add(child); } } while (testMethods.Count != 0) { XunitMethodInfo[] xunitTestMethods = GenericCollectionUtils.ConvertAllToArray( testMethods, x => XunitReflector.Wrap(x)); int nextTestIndex = testClassCommand.ChooseNextTest(xunitTestMethods); ITestCommand nextTestCommand = testCommands[nextTestIndex]; MethodInfo nextTestMethodInfo = testMethods[nextTestIndex]; testMethods.RemoveAt(nextTestIndex); testCommands.RemoveAt(nextTestIndex); passed &= RunTestMethod(nextTestCommand, nextTestMethodInfo, testClassCommand, testContext.TestStep); } } // Run ClassFinish behavior, if applicable. testContext.LifecyclePhase = LifecyclePhases.TearDown; ex = testClassCommand.ClassFinish() ?? ex; if (ex != null) { testContext.LogWriter.Failures.WriteException(ex, "Internal Error"); passed = false; } return(testContext.FinishStep(passed ? TestOutcome.Passed : TestOutcome.Failed, null)); } catch (Exception ex) { // Xunit probably shouldn't throw an exception in a test command. // But just in case... testContext.LogWriter.Failures.WriteException(ex, "Internal Error"); return(testContext.FinishStep(TestOutcome.Failed, null)); } }