Newer
Older
labs / tiddlers / content / labs / lab02 / _Labs_02_Create the Test Object.md

We need to create a Calculator object that we will test. To do this, we will:

  • Add a field to the class for the object.
  • Initialise that field in the setUp method.

We initialise via the setUp method since the setUp method will be run before each test method. This ensures that each test method will have a brand new object to test with and help to ensure that the tests are independent of each other.

Add the field:

private Calculator calc;

Initialise the field in the setUp method:

calc = new Calculator();