/// <summary> /// Starts a child step of the context. /// </summary> /// <param name="name">The name of the step.</param> /// <param name="codeElement">The code element, or null if none.</param> /// <param name="isTestCase">True if the step represents an independent test case.</param> /// <returns>The context of the child step.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is null.</exception> internal TestContext StartChildStep(string name, ICodeElementInfo codeElement, bool isTestCase) { Model.Tree.TestStep testStep = new Model.Tree.TestStep(inner.TestStep.Test, inner.TestStep, name, codeElement, false); testStep.IsTestCase = isTestCase; testStep.IsDynamic = true; return(PrepareContext(inner.StartChildStep(testStep), Sandbox.CreateChild())); }
private static TestResult ReportTestError(ITestCommand testCommand, Model.Tree.TestStep parentTestStep, Exception ex, string message) { ITestContext context = testCommand.StartPrimaryChildStep(parentTestStep); TestLog.Failures.WriteException(ex, message); return(context.FinishStep(TestOutcome.Error, null)); }
protected internal override TestResult RunImpl(ITestCommand rootTestCommand, Model.Tree.TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask("Running tests.", rootTestCommand.TestCount)) { // Note: We do not check options.SkipTestExecution here because we want to build up // the tree of data-driven test steps. So we actually check it later on in the // PatternTestExecutor. This is different from framework adapters // at this time (because they do not generally support dynamically generated data-driven tests). Sandbox sandbox = new Sandbox(); EventHandler canceledHandler = delegate { sandbox.Abort(TestOutcome.Canceled, "The user canceled the test run."); }; try { progressMonitor.Canceled += canceledHandler; TestAssemblyExecutionParameters.Reset(); PatternTestExecutor executor = new PatternTestExecutor(options, progressMonitor, formatter, converter, environmentManager); // Inlined to minimize stack depth. var action = executor.CreateActionToRunTest(rootTestCommand, parentTestStep, sandbox, null); action.Run(); return(action.Result); } finally { progressMonitor.Canceled -= canceledHandler; sandbox.Dispose(); } } }
public RunTestAction(PatternTestExecutor executor, ITestCommand testCommand, Model.Tree.TestStep parentTestStep, Sandbox parentSandbox, PatternTestActionsDecorator testActionsDecorator) { this.executor = executor; this.testCommand = testCommand; this.parentTestStep = parentTestStep; this.parentSandbox = parentSandbox; this.testActionsDecorator = testActionsDecorator; result = new TestResult(TestOutcome.Error); }
/// <summary> /// Creates a step. /// </summary> /// <remarks> /// <para> /// If <paramref name="isPrimary"/> is true, then all metadata from the <paramref name="test"/> /// is copied to the step. Otherwise the new step will have no metadata initially. /// </para> /// </remarks> /// <param name="test">The test to which the step belongs.</param> /// <param name="parent">The parent step, or null if creating a root step.</param> /// <param name="name">The step name.</param> /// <param name="codeElement">The point of definition of the step, or null if unknown.</param> /// <param name="isPrimary">True if the test step is primary.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> /// or <paramref name="test"/> is null.</exception> public PatternTestStep(PatternTest test, Model.Tree.TestStep parent, string name, ICodeElementInfo codeElement, bool isPrimary) : base(test, parent, name, codeElement, isPrimary) { }
/// <summary> /// Creates a primary step using the same name, code element and metadata /// as the test to which it belongs. /// </summary> /// <param name="test">The test to which the step belongs.</param> /// <param name="parent">The parent test step, or null if creating the root step.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="test"/> is null.</exception> public PatternTestStep(PatternTest test, Model.Tree.TestStep parent) : base(test, parent) { }
private static TestResult PublishOutcomeFromInvisibleTest(ITestCommand testCommand, Model.Tree.TestStep testStep, TestOutcome outcome) { switch (outcome.Status) { case TestStatus.Skipped: case TestStatus.Passed: // Either nothing interesting happened or the test was silently skipped during Before/After. return(new TestResult(TestOutcome.Passed)); case TestStatus.Failed: case TestStatus.Inconclusive: default: // Something bad happened during Before/After that prevented the test from running. ITestContext context = testCommand.StartStep(testStep); context.LogWriter.Failures.Write("The test did not run. Consult the parent test log for more details."); return(context.FinishStep(outcome, null)); } }
public RunTestAction CreateActionToRunTest(ITestCommand testCommand, Model.Tree.TestStep parentTestStep, Sandbox parentSandbox, PatternTestActionsDecorator testActionsDecorator) { return(new RunTestAction(this, testCommand, parentTestStep, parentSandbox, testActionsDecorator)); }