private static bool RunTestCommandAndFinishStep(ITestContext testContext, XunitTestClassCommand testClassCommand, XunitTestCommand testCommand) { try { testContext.LifecyclePhase = LifecyclePhases.Execute; XunitMethodResult result = testCommand.Execute(testClassCommand.ObjectUnderTest); return(LogMethodResultAndFinishStep(testContext, result, false)); } 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"); testContext.FinishStep(TestOutcome.Failed, null); return(false); } }
private static bool LogMethodResultAndFinishStep(ITestContext testContext, XunitMethodResult result, bool useXunitTime) { TimeSpan?testTime = useXunitTime ? (TimeSpan?)TimeSpan.FromSeconds(result.ExecutionTime) : null; if (!string.IsNullOrEmpty(result.Output)) { testContext.LogWriter.ConsoleOutput.Write(result.Output); } if (result is XunitPassedResult) { testContext.FinishStep(TestOutcome.Passed, testTime); return(true); } XunitFailedResult failedResult = result as XunitFailedResult; if (failedResult != null) { // Report the failure exception. testContext.LogWriter.Failures.WriteException( new ExceptionData( failedResult.ExceptionType ?? "", failedResult.Message ?? "", failedResult.StackTrace ?? "", ExceptionData.NoProperties, null), "Exception"); testContext.FinishStep(TestOutcome.Failed, testTime); return(false); } XunitSkipResult skipResult = result as XunitSkipResult; if (skipResult != null) { testContext.LogWriter.Warnings.Write("The test was skipped. Reason: {0}\n", string.IsNullOrEmpty(skipResult.Reason) ? "<unspecified>" : skipResult.Reason); testContext.FinishStep(TestOutcome.Skipped, testTime); return(true); } throw new NotSupportedException(String.Format("Unrecognized Xunit method result type: '{0}'.", result.GetType())); }
private static bool LogMethodResultAndFinishStep(ITestContext testContext, XunitMethodResult result, bool useXunitTime) { TimeSpan? testTime = useXunitTime ? (TimeSpan?)TimeSpan.FromSeconds(result.ExecutionTime) : null; if (!string.IsNullOrEmpty(result.Output)) testContext.LogWriter.ConsoleOutput.Write(result.Output); if (result is XunitPassedResult) { testContext.FinishStep(TestOutcome.Passed, testTime); return true; } XunitFailedResult failedResult = result as XunitFailedResult; if (failedResult != null) { // Report the failure exception. testContext.LogWriter.Failures.WriteException( new ExceptionData( failedResult.ExceptionType ?? "", failedResult.Message ?? "", failedResult.StackTrace ?? "", ExceptionData.NoProperties, null), "Exception"); testContext.FinishStep(TestOutcome.Failed, testTime); return false; } XunitSkipResult skipResult = result as XunitSkipResult; if (skipResult != null) { testContext.LogWriter.Warnings.Write("The test was skipped. Reason: {0}\n", string.IsNullOrEmpty(skipResult.Reason) ? "<unspecified>" : skipResult.Reason); testContext.FinishStep(TestOutcome.Skipped, testTime); return true; } throw new NotSupportedException(String.Format("Unrecognized Xunit method result type: '{0}'.", result.GetType())); }