How to mock in PowerUnit

People keep asking me how to do mock in PowerUnit, here is my solution.

Unfortunately, PowerBuilder doesn’t have interface concept yet. We have to use class inheritance to work around.

Also, constructor parameter is another missing must-have for mocking. A customized of_init(parms) function is needed to simulate this.

source code of nvo_developer:
// instance variables
nvo_drink iDrink

nvo_drink drink
drink = create nvo_drink

//public subroutine of_init (readonly nvo_drink adrink);
iDrink = aDrink
//public function string of_work ();
if ( not isValid(iDrink)   ) then return "No drink, no work."
return iDrink.Name

One thought on “How to mock in PowerUnit

  1. Frank is there a way using PBUnit to test a CRUD GUI interface where the insert and updates are made directly to DW (Values are entered in DW Fields intead of collecting them in Objects like SLE)and assert the values for each field? Could you help with this? I have been diggin on Unit Test for PB, but if I cannot do it directly on DWs it makes no sense for me.. I should re code the whole application. I appreciatte your help. Thanks in advanced.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s