10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
6318
6418
6518
6618
6718
680
6918
700
710
720
730
7418
750
760
770
780
7918
800
810
820
830
8418
8518
860
870
/++
When you run complex tests, or tests that take a lot of time, it helps
to mark certain areas as steps, to ease the debug or to improve the report.
A good usage is for running BDD tests where a step can be steps from the
`Gherkin Syntax` or UI Automation tests.
Copyright: © 2017 Szabo Bogdan
License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
Authors: Szabo Bogdan
+/
module trial.step;
import trial.runner;
import trial.interfaces;
import std.datetime;
import std.stdio;
/** A step structure. Creating a Step will automatically be added to the current step as a child
* The steps can be nested to allow you to group steps as with meanigful names.
*
* The steps ends when the Struct is destroyed. In order to have a step that represents a method
* assign it to a local variable
*
* Examples:
* ------------------------
* void TestSetup() @system
* {
* auto aStep = Step("Given some precondition");
*
* Step("Some setup");
* performSomeSetup();
*
* Step("Other setup");
* performOtherSetup();
* }
* // will create this tree:
* // Test
* // |
* // +- Given some precondition
* // |
* // +- Some setup
* // +- Other setup
* ------------------------
*/
struct Step
{
static {
/// The current suite name. Do not alter this global variable
string suite;
/// The current test name. Do not alter this global variable
string test;
}
@disable
this();
private {
StepResult step;
}
/// Create and attach a step
this(string name) {
step = new StepResult;
step.name = name;
step.begin = Clock.currTime;
step.end = Clock.currTime;
if(LifeCycleListeners.instance is null) {
writeln("Warning! Can not set steps if the LifeCycleListeners.instance is not set.");
return;
}
LifeCycleListeners.instance.begin(suite, test, step);
}
/// Mark the test as finished
~this() {
if(LifeCycleListeners.instance is null) {
writeln("Warning! Can not set steps if the LifeCycleListeners.instance is not set.");
return;
}
step.end = Clock.currTime;
LifeCycleListeners.instance.end(suite, test, step);
}
}