Testing the Money package content

The purpose of these tests is to validate the behavior of the Money and MoneyBag classes (cf. Figure 15).

Figure 15: Content of the Money package.

Prior to any test cases specifications, you need to describe the test context.

  1. right click on the Money package create a test package. The MoneyTest package and diagram are created;

  2. right click on the MoneyTest package and create a test context. Name it MoneySuite. The test context will appear in the MoneyTest Diagram;

  3. for the test cases, we need to manipulate two instances of Money. In the TestContext diagram, you can see that only one money internal part has been created. Name it money1;

  4. thanks to Modelio facilities, clone the money internal part and name it money2. Unmask this new internal part on the test context diagram and check that it is stereotyped SUT.

We can now specify the first test case whose objective is to check that two amounts of the same currency are well added. For this:

  1. right click on MoneySuite and create a test case. The wizard is opened;

  2. name the test case addSameMoney and describe the test case objective, e.g. “ensure that the Money class returns an object of type Money with the correct amount and currency” (cf. Figure 16);

  3. Click OK to validate the wizard content;

Figure 16: addSameMoney() test case.

On the MoneyTest diagram, you can check that a test objective has been generated with the content you specified (cf. Figure 17).

Figure 17: Money test context specification.

Furthermore, the generated sequence diagram corresponding to the test case is opened. It is pre-filled with lifelines and creation messages according to the test context internal parts. It also contains a state invariant specifying the expected result (verdict) of the test case.

  1. for this test case, remove the lifeline of the MoneyBag;

  2. select the creation message to the money1 part and fill its argument property field with the values passed to the Money() constructor, e.g. 20, “USD”; do the same with money2 and e.g. 50, “USD” values;

  3. create a synchronous message from moneysuite to money1 and select the add operation. Specify money2 as argument;

  4. select the return message and say its name to be add(–): new Money(70, “USD”)_. This specifies the expected result of the message;

  5. _check that the result is conforming to the Figure 18.

Figure 18: Specification of the addSameMoney() test case.

You can now exercise yourself to specify the addDifferentMoney() test case like on Figure 19. The test objective is “ Ensure that the Money class returns an object of type MoneyBag with the currencies of the two Money objects that were added during the call to the add operation”.

Figure 19: Specification of the addDifferentMoney() test case.

image020.png (11.4 KB) admin admin, 10 October 2014 16:40

image021.jpg (35.5 KB) admin admin, 10 October 2014 16:40

image022.jpg (15.5 KB) admin admin, 10 October 2014 16:40

image024.png (14.6 KB) admin admin, 10 October 2014 16:40

image018.png (21.9 KB) admin admin, 10 October 2014 16:40