本文整理汇总了C#中NUnit.Core.TestResult.SetResult方法的典型用法代码示例。如果您正苦于以下问题:C# TestResult.SetResult方法的具体用法?C# TestResult.SetResult怎么用?C# TestResult.SetResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Core.TestResult
的用法示例。
在下文中一共展示了TestResult.SetResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunTest
TestResult RunTest(EventListener listener)
{
listener.TestStarted(base.TestName);
TestResult nunitTestResult = new TestResult(this);
if (_pendingException != null)
{
nunitTestResult.Failure(_pendingException.Message, _pendingException.StackTrace, FailureSite.Test);
}
else if (RunState == RunState.NotRunnable)
{
nunitTestResult.SetResult(ResultState.NotRunnable, IgnoreReason, "", FailureSite.Test);
}
else
{
var testResult = SpecificationRunner.RunTest(this._testContext, new List<string>());
NativeTestResult.ApplyToNunitResult(testResult, nunitTestResult);
}
listener.TestFinished(nunitTestResult);
return nunitTestResult;
}
示例2: WhenResultIsSet_IndexReflectsResultState
public void WhenResultIsSet_IndexReflectsResultState(ResultState resultState, int expectedIndex)
{
TestSuiteTreeNode node = new TestSuiteTreeNode(new TestInfo(testCase));
TestResult result = new TestResult(testCase);
result.SetResult(resultState, null, null);
node.Result = result;
Assert.AreEqual(expectedIndex, node.ImageIndex);
Assert.AreEqual(expectedIndex, node.SelectedImageIndex);
Assert.AreEqual(resultState.ToString(), node.StatusText);
}
示例3: Run
public override TestResult Run(EventListener listener, ITestFilter filter)
{
listener.TestStarted(base.TestName);
long ticks = DateTime.Now.Ticks;
TestResult result = new TestResult(this);
result.SetResult(ResultState.NotRunnable, "Specification not implemented.", null, FailureSite.Test);
double num3 = ((double)(DateTime.Now.Ticks - ticks)) / 10000000.0;
result.Time = num3;
listener.TestFinished(result);
return result;
}
示例4: SetResult_Inconclusive
public void SetResult_Inconclusive()
{
TestSuiteTreeNode node = new TestSuiteTreeNode(testCaseInfo);
TestResult result = new TestResult(testCaseInfo);
result.SetResult(ResultState.Inconclusive, null, null);
node.Result = result;
Assert.AreEqual("MockTest1", node.Result.Name);
Assert.AreEqual(TestSuiteTreeNode.InconclusiveIndex, node.ImageIndex);
Assert.AreEqual(TestSuiteTreeNode.InconclusiveIndex, node.SelectedImageIndex);
Assert.AreEqual(result.ResultState.ToString(), node.StatusText);
}
示例5: Run
public override TestResult Run(EventListener listener, ITestFilter filter)
{
// TODO: Implement logic required for filtering.
listener.TestStarted(this.TestName);
long startTime = DateTime.Now.Ticks;
var result = new TestResult(this);
try
{
_engine.ExecuteScriptFile(_scriptPath);
result.Success();
}
catch (AssertionException assertEx)
{
result.SetResult(ResultState.Failure, assertEx.Message, assertEx.StackTrace, FailureSite.Test);
}
catch (InconclusiveException inconclusiveEx)
{
result.SetResult(ResultState.Inconclusive, inconclusiveEx.Message, inconclusiveEx.StackTrace);
}
catch (Exception ex)
{
result.Error(ex);
}
finally
{
long stopTime = DateTime.Now.Ticks;
double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
result.Time = time;
listener.TestFinished(result);
}
return result;
}
示例6: CreateTestResult
public TestResult CreateTestResult(TestType type, string fullName,
ResultState state = ResultState.Success,
Func<IEnumerable<TestResult>> children = null,
string stackTrace = null,
string description = null,
IList categories = null,
string agentName = null)
{
description = description ?? RandomValuesGenerator.GetRandomValue<string>();
agentName = agentName ?? RandomValuesGenerator.GetRandomValue<string>();
var splitted = (fullName ?? string.Empty).Split(new[]{'.'}, StringSplitOptions.RemoveEmptyEntries);
var childResults = children != null ? children() : new TestResult[0];
var testResult = new TestResult(new TestInfoWrapper
{
TestName = new TestName
{
FullName = fullName,
Name = splitted.Length > 0 ? splitted[splitted.Length - 1] : string.Empty
},
Categories = categories,
IsSuite = type != TestType.TestMethod,
TestCount = type == TestType.TestMethod ? 1 : RandomValuesGenerator.GetRandomValue<int>(),
TestType = type.ToString()
})
{
AssertCount = 1,
Time = RandomValuesGenerator.GetRandomValue<double>()
};
if (state != ResultState.Success)
testResult.SetResult(state,
description,
stackTrace);
else
testResult.Success(description);
testResult.SetAgentName(agentName);
foreach (var childResult in childResults)
{
testResult.AddResult(childResult);
}
return testResult;
}
示例7: ApplyToNunitResult
public static TestResult ApplyToNunitResult(TestResultShim shim, TestResult result)
{
switch (shim.Status)
{
case TestResultShim.Result.Successs:
result.Success();
break;
case TestResultShim.Result.Error:
result.SetResult(ResultState.Error, shim.FailureReason, shim.FailureStackTrace, GetNUnitFailureSite(shim.FailureSite));
break;
default:
throw new ArgumentOutOfRangeException();
}
result.Time = shim.ExecutionTime.Seconds;
return result;
}
示例8: SetUp
public void SetUp()
{
MethodInfo fakeTestMethod = GetType().GetMethod("FakeTestMethod", BindingFlags.Instance | BindingFlags.NonPublic);
fakeNUnitTest = new NUnitTestMethod(fakeTestMethod);
fakeNUnitResult = new NUnitTestResult(fakeNUnitTest);
fakeNUnitResult.SetResult(ResultState.Success, "It passed!", null);
fakeNUnitResult.Time = 1.234;
testLog = new FakeFrameworkHandle();
testConverter = new TestConverter(new TestLogger(), ThisAssemblyPath);
testConverter.ConvertTestCase(fakeNUnitTest);
Assert.NotNull(testConverter.GetCachedTestCase(fakeNUnitTest.TestName.UniqueName));
listener = new NUnitEventListener(testLog, testConverter);
}
示例9: CanMakeTestResultFromNUnitTestResult
public void CanMakeTestResultFromNUnitTestResult()
{
// This should put the TestCase in the cache
var cachedTestCase = testConverter.ConvertTestCase(fakeNUnitTest);
var nunitResult = new NUnitTestResult(fakeNUnitTest);
nunitResult.SetResult(ResultState.Success, "It passed!", null);
nunitResult.Time = 1.234;
var testResult = testConverter.ConvertTestResult(nunitResult);
var testCase = testResult.TestCase;
Assert.That(testCase, Is.SameAs(cachedTestCase));
CheckTestCase(testCase);
Assert.That(testResult.Outcome, Is.EqualTo(TestOutcome.Passed));
Assert.That(testResult.ErrorMessage, Is.EqualTo("It passed!"));
Assert.That(testResult.Duration, Is.EqualTo(TimeSpan.FromSeconds(1.234)));
}
示例10: NUnitTestResult
private TestResult NUnitTestResult(IResultSummary concordionResult, string resultPath)
{
var testResult = new TestResult(this);
if (concordionResult.HasExceptions)
{
var errorDetails = concordionResult.ErrorDetails.First();
testResult.Error(errorDetails.Exception);
testResult.SetResult(testResult.ResultState,
resultPath + Environment.NewLine + testResult.Message,
testResult.StackTrace);
}
else if (concordionResult.HasFailures)
{
var failureDetails = concordionResult.FailureDetails.First();
testResult.Failure(resultPath + Environment.NewLine + failureDetails.Message, failureDetails.StackTrace);
} else
{
testResult.Success(resultPath);
}
return testResult;
}
示例11: GetNoAvailableAgentsFailure
/// <summary>
/// Gets the no available agents failure.
/// </summary>
/// <param name="test">The test.</param>
/// <param name="exception">The exception.</param>
/// <returns></returns>
public static TestResult GetNoAvailableAgentsFailure(TestUnitWithMetadata test, Exception exception)
{
var result = GetResultForTest(test.Test, exception);
TestResult suite = result;
while (suite.HasResults)
{
suite = (TestResult)suite.Results[0];
}
// A test can be either test suite or test case
// Here it is a suite
if (test.Test.Info.IsSuite && test.Children.Any())
{
foreach (var child in test.Children)
{
var childResult = new TestResult(child.Test.Info);
childResult.SetResult(ResultState.NotRunnable, exception, FailureSite.Parent);
suite.AddResult(childResult);
}
}
return result;
}
示例12: RecordException
protected virtual void RecordException( Exception exception, TestResult testResult, FailureSite failureSite )
{
if (exception is NUnitException)
exception = exception.InnerException;
// Ensure that once a test is cancelled, it stays cancelled
ResultState finalResultState = testResult.ResultState == ResultState.Cancelled
? ResultState.Cancelled
: NUnitFramework.GetResultState(exception);
testResult.SetResult(finalResultState, exception, failureSite);
}
示例13: RunTest
/// <summary>
/// The doRun method is used to run a test internally.
/// It assumes that the caller is taking care of any
/// TestFixtureSetUp and TestFixtureTearDown needed.
/// </summary>
/// <param name="testResult">The result in which to record success or failure</param>
public virtual TestResult RunTest()
{
DateTime start = DateTime.Now;
TestResult testResult = new TestResult(this);
TestExecutionContext.CurrentContext.CurrentResult = testResult;
try
{
RunSetUp();
#if CLR_2_0 || CLR_4_0
RunBeforeActions(testResult);
#endif
RunTestCase( testResult );
}
catch(Exception ex)
{
// doTestCase handles its own exceptions so
// if we're here it's a setup exception
if (ex is ThreadAbortException)
Thread.ResetAbort();
RecordException(ex, testResult, FailureSite.SetUp);
}
finally
{
#if CLR_2_0 || CLR_4_0
RunAfterActions(testResult);
#endif
RunTearDown( testResult );
DateTime stop = DateTime.Now;
TimeSpan span = stop.Subtract(start);
testResult.Time = (double)span.Ticks / (double)TimeSpan.TicksPerSecond;
if (testResult.IsSuccess)
{
if (this.Properties.Contains("MaxTime"))
{
int elapsedTime = (int)Math.Round(testResult.Time * 1000.0);
int maxTime = (int)this.Properties["MaxTime"];
if (maxTime > 0 && elapsedTime > maxTime)
testResult.Failure(
string.Format("Elapsed time of {0}ms exceeds maximum of {1}ms",
elapsedTime, maxTime),
null);
}
if (testResult.IsSuccess && testResult.Message == null &&
Environment.CurrentDirectory != TestExecutionContext.CurrentContext.prior.CurrentDirectory)
{
// TODO: Introduce a warning result state in NUnit 3.0
testResult.SetResult(ResultState.Success, "Warning: Test changed the CurrentDirectory", null);
}
}
}
log.Debug("Test result = " + testResult.ResultState);
return testResult;
}
示例14: GetResult
/// <summary>
/// Gets the result.
/// </summary>
/// <param name="exception">The exception.</param>
/// <param name="description">The description.</param>
/// <param name="testType">Type of the test.</param>
/// <param name="fullName">The full name.</param>
/// <param name="isSuite">if set to <c>true</c> [is suite].</param>
/// <returns></returns>
public static TestResult GetResult(Exception exception, string description, string testType, string fullName, bool isSuite = true)
{
var result = new TestResult(new TestDataProvider
{
TestName = new TestName
{
FullName = fullName,
Name = fullName
},
IsSuite = isSuite,
TestType = testType,
});
result.SetResult(ResultState.NotRunnable,
exception == null ? description : exception.Message,
exception == null ? null : exception.StackTrace);
return result;
}
示例15: RecordException
protected virtual void RecordException( Exception exception, TestResult testResult, FailureSite failureSite )
{
if (exception is NUnitException)
exception = exception.InnerException;
testResult.SetResult(NUnitFramework.GetResultState(exception), exception, failureSite);
}