Common Testing Methods

BaseSpec

It is important to get familiar with TestBox before adventuring into ColdBox testing. Therefore, we suggest you reference the TestBox Docs (https://testbox.ortusbooks.com/primers/testbox-bdd-primer) or the TestBox API Docs (http://apidocs.ortussolutions.com/testbox/current). Below you can see a few of the common methods available to you.
1
// quick assertion methods
2
assert( expression, [message] )
3
fail(message)
4
5
// Life Cycle Methods
6
beforeEach( body )
7
afterEach( body )
8
aroundEach( body, spec )
9
10
// Spec Methods
11
describe( title, body, labels, asyncAll, skip )
12
xdescribe( title, body, labels, asyncAll )
13
fdescribe( title, body, labels, asyncAll )
14
15
feature( title, body, labels, asyncAll, skip )
16
xfeature( title, body, labels, asyncAll )
17
ffeature( title, body, labels, asyncAll )
18
19
20
it( title, body, labels, skip )
21
xit( title, body, labels )
22
fit( title, body, labels, skip )
23
24
// Expectations
25
expect( actual )
26
27
// extensions
28
addMatchers( matchers )
29
addAssertions( assertions )
30
31
// runners
32
runRemote( testSpecs, testSuites, deubg, reporter );
33
34
// utility methods
35
console( var, top )
36
debug( var, deepCopy, label, top )
37
clearDebugBuffer()
38
getDebugBuffer()
39
print( message )
40
printLn( message )
41
42
// mocking methods
43
makePublic( target, method, newName )
44
querySim( queryData )
45
getmockBox( generationPath )
46
createEmptyMock( className, object, callLogging )
47
createMock( className, object, clearMethods, callLogging )
48
prepareMock( object, callLogging )
49
createStub( callLogging, extends, implements )
50
getProperty( target, name, scope, defaultValue )
Copied!

BaseTestCase

As we have seen that our BaseTestCase inherits from the BaseSpec you get all the goodness of TestBox. However, the BaseTestCase also has a wealth of methods to assist in your testing adventures: https://apidocs.ortussolutions.com/coldbox/6.0.0/coldbox/system/testing/BaseTestCase.html
Here are some useful methods:
1
announce(any state, [struct data='[runtime expression]'], [boolean async='false'], [boolean asyncAll='false'], [boolean asyncAllJoin='true'], [any asyncPriority='NORMAL'], [numeric asyncJoinTimeout='0'])
2
3
// Getters
4
getCache(any cacheName='default')
5
getCacheBox()
6
getController()
7
getFlashScope()
8
getHandlerResults()
9
getInstance([any name], [struct initArguments='[runtime expression]'], [any dsl])
10
getInterceptor(any interceptorName)
11
getLogBox()
12
getRenderData()
13
getRenderedContent()
14
getRequestContext()
15
getStatusCode()
16
getUtil()
17
getWireBox()
18
19
// Get Mocking Objects
20
getMockController()
21
getMockModel(any name, [boolean clearMethods='false'])
22
getMockRequestContext([boolean clearMethods='false'], [any decorator])
23
24
25
//Reset the persistence of the unit test coldbox app, basically removes the controller from application scope.
26
reset([boolean clearMethods='false'], [any decorator])
27
28
// Prepare a ColdBox request
29
setup()
Copied!
Last modified 1yr ago
Copy link