-
Notifications
You must be signed in to change notification settings - Fork 8
Description
A question about the mocking mechanism in OmnisTAP:
I noticed that for every test class in the $setup gets a line where a mock of the production class
Do $cinst.$mock($objects.oTree) Returns iorMock
This got me confused how the mocking system is working. In my perception you only mock the objects which you do not want to test and want to communicate to eg a database. I looked at the example and there also the production class is mocked, certain methods are mocked, the method to test is called and then the mocks are asserted.
Let say I want to mock a object used as a local variable in an object. How do I do that? With UnitTest framwork based on OmnisUnitTest. I do something like this:
Do $clib.$classes.$add(kObjectclass,'oTreeOrg') Returns newObjectRef
Do newObjectRef.$classdata.$assign($libs.OmniHisSql.$classes.oTree.$classdata)
Do $libs.OmniHisSql.$objects.oTree.$classdata.$assign($clib.$classes.oTree.$classdata)
; Do some tests
;
Do loForest.$getTreeCount() Returns liTreeCount
; Do some assertions
Do $libs.OmniHisSql.$classes.oTree.$classdata.$assign($clib.$classes.oTreeOrg.$classdata)
Do $clib.$classes.$remove($clib.$classes.oTreeOrg.$ref())
I presume that this should be possible with OmnisTAP, but I did not get it working yet. Below an example of my failed attempt.
Do $cinst.$mock($objects.oTree) Returns loTreeMock
Do $objects.oForest.$newref() Returns lorForest
; Set Mock properties
Do loTreeMock.$mock("$isTree").$expect(kTrue).$return_boolean(kTrue)
Do lorForest.$getTreeCount() Returns liTreeCount
Do ioTAP.$is_number(liTreeCount,liTreeCount,'Get the number of trees in the Forest')
Do $cinst.$asserts()
Could you help me with this. What am I missing?