Class DefaultExecutor

The default test executor runs test in sequential order in a single thread

class DefaultExecutor
  : ITestExecutor
  , IStepLifecycleListener
  , IAttachmentListener ;

Methods

NameDescription
attach (attachment) Called when an attachment is ready
begin (suite, test, step) Add the step result and update the other listeners on every step
beginExecution (_param_0) It does nothing
end (suite, test, step) Update the other listeners on every step
endExecution () Return the result for the last executed suite
execute (testCase) Execute a test case
createTestResult (testCase) Convert a test case to a test result
runTest (testCase, testResult) Run a test case

Example

Executing a test case that throws a PendingTestException should mark the test result as pending instead of a failure

auto old = LifeCycleListeners.instance;
LifeCycleListeners.instance = new LifeCycleListeners;
LifeCycleListeners.instance.add(new DefaultExecutor);

scope (exit) {
  LifeCycleListeners.instance = old;
}

void test() {
  throw new PendingTestException();
}

auto testCase = const TestCase("Some.Suite", "test name", &test, []);
auto result = [testCase].runTests;

result.length.should.equal(1);
result[0].tests[0].status.should.equal(TestResult.Status.pending);

Example

Executing a test case should set the right begin and end times

import core.thread;
auto old = LifeCycleListeners.instance;
LifeCycleListeners.instance = new LifeCycleListeners;
LifeCycleListeners.instance.add(new DefaultExecutor);

scope (exit) {
  LifeCycleListeners.instance = old;
}

void test() {
  Thread.sleep(1.msecs);
}

auto testCase = const TestCase("Some.Suite", "test name", &test, []);

auto begin = Clock.currTime;
auto result = [ testCase ].runTests;
auto testResult = result[0].tests[0];

testResult.begin.should.be.greaterThan(begin);
testResult.end.should.be.greaterThan(begin + 1.msecs);