Apply unit-test to PFC application

Global variables are evil, so in your PFC app, you should try to reduce the global variables to only one: n_cst_appmanager.

Then, in your objects, add a function called of_set_appmanager to set this global variable to it’s instance one. Unfortunately PB’s constructor doesn’t take parameters, we cannot use constructor injection for PowerBuilder objects. Unfortunately, object constructor in PB does not take any parameters,   yet.  So constructors cannot be used to accomplish dependency injection in PB. (Thanks Kpu for helping me out of this weird Engrlish expression.)

Visual objects can not be unit-tested, actually, if you try

datawindow ldw_1
ldw_1 = create ldw_1

PowerBuilder doesn’t report any compile errors, but, datawindow’s constructor event won’t be triggered in this scenario. Same thing will happen if you try any (visual) userobject.

I tried to adopt MVP pattern (kind of, becuase PB doesn’t support interface) to my userobject/window to make unit-test possible. The new term of MVP, Passive View, makes more sense for pattern newbies. Your UI should not bee too smart, which means don’t put too many logic in it. So, you have to extract all retrieve functions into the presenter behind this UI/view. In another word, SetTransObject(SQLCA) won’t need in UI.

Advertisements

One thought on “Apply unit-test to PFC application

  1. You need to use OpenUserObject or OpenUserObjectWithParm for visual controls. With the second one, you can pass whatever you want in the Message object. Note that you also need to call CloseUserObject when you close the window.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s