addParameterizedTests
assertNodesAreEqual
assertMethodWasCalled
assertMethodWasNotCalled
setAfterAll
setAfterEach
setBeforeAll
setBeforeEach
Allows to test multiple parameters in a sequence. The testName
string can be interpolated with values that implement ifToStr
interface. For instance:
ts.addParameterizedTests([
1,
2
], "should check if the {0} value is greater than 0", function (ts as Object, param as Integer) as String
return ts.assertTrue(param > 0)
end function)
or with object:
ts.addParameterizedTests([
{ value: 1, expected: true },
{ value: 2, expected: true },
], "should check if the ${value} value is greater than 0", function (ts as Object, param as Integer) as String
return ts.assertEqual(param.value > 0, param.expected)
end function)
Params:
paramsList
:Object
- array of test valuestestName
:String
- test descriptiontestFunction
:Function
- takes the arguments:ts
:Object
- the TestSuite objectparam
:Dynamic
- the single value from the array
Recursively checks if two given nodes are equal. This is not simple comparision of node references. The method deeply compares node's field values including their children.
Params:
expected
:Object
- nodetested
:Object
- nodemsg = ""
:String
- additional message when test fails
It checks if the mocked method/function is called. It works with manual and automatic mocks. For example:
' My tested entities
function add(a as Integer, b as Integer) as Integer
return a + b
end function
function Math() as Object
prototype = {}
prototype.add = function (a as Integer, b as Integer) as Integer
return a + b
end sub
return prototype
end function
' My test suite
@mock sum.brs
@mock Math.brs
' ...
ts.addTest("checks if function was called", function (ts as Object) as String
result = add(1, 2)
return ts.assertMethodWasCalled("add", { a: 1, b: 2 }, { times: 1, strict: true })
end function)
' ...
ts.addTest("checks if methods was called", function (ts as Object) as String
result = Math().add(1, 2)
return ts.assertMethodWasCalled("Math.add", { a: 1, b: 2 }, { times: 1, strict: true })
end function)
Params:
methodPath
:String
- function or method nameparams = {}
:Object
- function or method argumentsoptions = {}
:Object
times
:Integer
- how many times it should be calledstrict
:Boolean
- affects how the params are compared. Whentrue
the params object must match the arguments types and values (1 to 1 equality). Iffalse
the params object can contain some of the passed arguments that are tested
msg = ""
:String
- additional message when test fails
Opposite to assertMethodWasCalled
. It checks if function/method was not called with given params or times.
Params:
methodPath
:String
- function or method nameparams = {}
:Object
- function or method argumentsoptions = {}
:Object
times
:Integer
- how many times it should be calledstrict
:Boolean
- affects how the params are compared. Whentrue
the params object must match the arguments types and values (1 to 1 equality). Iffalse
the params object can contain some of the passed arguments that are tested
msg = ""
:String
- additional message when test fails
Runs a function after all the tests in the file have completed.
Params:
callback
:setupOrTeardownCallback
Example:
ts = KopytkoTestSuite()
ts.setAfterAll(sub (ts as Object)
?"TestSuite finished: ";ts.name
end sub)
Runs a function after each one of the tests in the file completes.
Params:
callback
:setupOrTeardownCallback
Runs a function before all the tests in the file run.
Params:
callback
:setupOrTeardownCallback
Runs a function before each one of the tests in the file runs.
Params:
callback
:setupOrTeardownCallback
Params:
ts
:Object
- the TestSuite object