Setup and Teardown
TestBox not only provides you with global life-cycle methods but also with localized test methods. This is a great way to keep your tests DRY (Do not repeat yourself)! TestBox provides the setup( currentMethod ) and teardown( currentMethod ) methods that each receives the name of the test method in question. which as their names indicate, they execute before a test and after a test in a test bundle.
1
component displayName="TestBox xUnit suite" labels="railo,cf"{
2
3
function setup( currentMethod ){
4
application.wirebox = new coldbox.system.ioc.Injector();
5
structClear( request );
6
}
7
8
function teardown( currentMethod ){
9
structDelete( application, "wirebox" );
10
structClear( request );
11
}
12
13
function testThrows(){
14
$assert.throws(function(){
15
var hello = application.wirebox.getInstance( "myINvalidService" ).run();
16
});
17
}
18
19
function testNotThrows(){
20
$assert.notThrows(function(){
21
var hello = application.wirebox.getInstance( "MyValidService" ).run();;
22
});
23
}
24
25
}
Copied!
Last modified 3yr ago
Copy link