Navigation:  Tutorials > Creating a GUI Application >

Testing the Domain Models

Previous pageReturn to chapter overviewNext page

Now we have completed the first pass at designing our domain model classes, it is a suitable time to test the functionality. Evaluate the following a line at a time in a Workspace.

a := PersonalMoney new.

a owner: 'My Name'.

b := PersonalAccount new.

b name: 'My Current Account'.

b accountNumber: 'ABC345'.

b initialBalance: 500.

 

You can inspect either of these two instances to ensure they are correct, then add the account to the money application:

a addAccount: b

 

Next create one or more transactions and add these to the account:

c := PersonalAccountTransaction new.

c description: 'Brown Shoes'.

c amount: 50.65.

b addTransaction: c.

 

When done, you can ask for the current balance of the account as follows (remember to display the answer):

b currentBalance

 

As you can see it is easy to exercise all of the functionality in your domain classes from a Smalltalk workspace before progressing to the user interface programming. It is good practice to clean up any variables that you create during testing (such as a, b, c here) to avoid them holding on to unwanted instances of your test objects. The easiest way to do this is simply to close the workspace in which they were declared. However, in this case these temporary values may be useful for trying out your user interface later. Keep them around now, but remember to close the workspace later on when you've finished.