Developing your Tests with Database and N-Tiers support
What can I do with database?
ProUnit lets you easily handle data with database. The goal is to be able to control database records generated by a program according to specific input data.
For instance, ProUnit can work like this:
- import records from file "initial_data.d" to a physical table (overwriting existing records)
- run a procedure to test (that may change database records)
- extract some records from a physical table to a temp-table (A)
- load records from file "expected_result.d" to a temp-table (B)
- compare temp-tables (A and B)
In Client / AppServer environment with full N tiers (client not connected to any database), ProUnit can work like this:
- connect same databases on client than AppServer has connected to
- import records from file "initial_data.d" to physical table (overwriting existing records)
-
disconnect databases from client
- run a procedure to test on AppServer (this procedure may change some database records)
- connect same database on client than AppServer has connected to
- extract some records from a physical table to a temp-table (A)
- load records from file "expected_result.d" to a temp-table (B)
- compare temp-tables (A and B)
- disconnect databases from client
Source code sample
DEFINE VARIABLE hTTExpected AS HANDLE.
DEFINE VARIABLE hTTGot AS HANDLE.
/*------------------------------------------------------------------------------
Some code to initialize the environment or database before running the test.
------------------------------------------------------------------------------*/
PROCEDURE initialize:
END.
/*------------------------------------------------------------------------------
Some code run before every test to reset internal states, if needed.
------------------------------------------------------------------------------*/
PROCEDURE setUp:
END.
/*------------------------------------------------------------------------------
Some code run after a test to restore, log or something else.
------------------------------------------------------------------------------*/
PROCEDURE tearDown:
END.
/*------------------------------------------------------------------------------
Dispose everything, free resource, close files, disconnect databases, etc.
------------------------------------------------------------------------------*/
PROCEDURE dispose:
END.
/*------------------------------------------------------------------------------
Full database test
------------------------------------------------------------------------------*/
PROCEDURE testDatabase:
/* Connect to database, inject initial data, then disconnect from database */
RUN LocalConnectAppServerDB(INPUT hAppServer, "myDBLogicalName") NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
RUN LoadDFileToDBTable(INPUT "c:\initial.d", INPUT "MY_TABLE", INPUT NO, INPUT YES) NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
RUN LocalDisconnectAppServerDB NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
/* Run our program to be tested. This program may change MY_TABLE records. */
RUN my_test.p ON hAppServer (INPUT ....) NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
/* Connect to database, gather changed data, then disconnect from database */
RUN LocalConnectAppServerDB(INPUT hAppServer, "myDBLogicalName") NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
/* Create temp-tables like physical table */
RUN CreateTTLikePhysicalDBTable(INPUT "MY_TABLE", INPUT "a_name_for_your_tt", OUTPUT hTTExpected) NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
RUN CreateTTLikePhysicalDBTable(INPUT "MY_TABLE", INPUT "another_name_for_your_tt", OUTPUT hTTGot) NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
RUN ExportDBTableToTempTableViaQuery(INPUT "MY_TABLE", INPUT hTTGot, INPUT YES, INPUT NO, INPUT "where somefield = 12") NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
RUN LoadDFileToTempTable(INPUT "c:\expected.d", INPUT hTTExpected, INPUT YES, INPUT NO) NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
RUN assertEqualsTT(hTTExpected, hTTGot, "").
RUN DeleteTTByHandle(INPUT hTTExpected).
RUN DeleteTTByHandle(INPUT hTTGot).
RUN LocalDisconnectAppServerDB NO-ERROR.
IF ERROR-STATUS:ERROR THEN
MESSAGE RETURN-VALUE SKIP ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX WARNING.
END.
|
Procedures
During your test you can use all of these procedures:
| Method | Description | Example |
|---|---|---|
| LoadDFileToTempTable |
Dynamically load data from .d file to a temp-table. Parameters:
|
RUN LoadDFileToTempTable(INPUT "c:\expected.d", INPUT hTTExpected, |
| LoadDFileToDBTable |
Dynamically load data from .d file to a physical table. Parameters:
|
RUN LoadDFileToDBTable(INPUT "c:\expected.d", INPUT "MY_TABLE", |
| LoadDFilesToDBTablesFromDirectory |
Dynamically load a set of .d files to many physical table. Parameters:
|
RUN LoadDFilesToDBTablesFromDirectory(INPUT "c:\data", INPUT NO, |
| ExportDBTableToTempTableViaQuery |
Dynamically export data from a physical table to a temp-table, according to a query. Parameters:
|
RUN ExportDBTableToTempTableViaQuery(INPUT "MY_TABLE", INPUT hTTGot, |
| CreateTTLikePhysicalDBTable |
Create a dynamic temp-table like a physical database table. Parameters:
|
RUN CreateTTLikePhysicalDBTable(INPUT "MY_TABLE", INPUT "a_name_for_your_tt", |
| DeleteTTByHandle |
Delete a dynamic temp-table from its handle. Parameters:
|
RUN DeleteTTByHandle(INPUT hTTExpected). |
| DeleteDBTableRecordsViaQuery |
Delete records from physical table according to a query. Parameters:
|
RUN DeleteDBTableRecordsViaQuery(INPUT "MY_TABLE", |
| LocalConnectAppServerDB |
Query AppServer for connected databases and connect some of them to current session Parameters:
|
RUN LocalConnectAppServerDB(INPUT hAppServer, "myDBLogicalName") NO-ERROR. |
| LocalDisconnectAppServerDB | Disconnect previously connected databases got from AppServer. |
RUN LocalDisconnectAppServerDB NO-ERROR. |
Architecture and integration to N-Tiers Progress Sessions
In this part, you can see a diagram detailing ProUnit integration to your own framework (if any) in a N-Tiers architecture.

Here are details of steps:
- AppServer session starts
- AppServer session connects to databases
- Client session starts
- Client session connects to AppServer session
- Your ProUnit test program use ProUnit framework to ask AppServer for database connection list and connect to some databases using same parameters as AppServer did
- Once the ProUnit framework is connected to database, your test program acces it and disconnectusing ProUnit framework
