Side effects come into play when an object that we are testing is modified by the method under test. We can explicitly test for this.


You can find the code relating to this tutorial on Github in the /java/util/simplesteps folder.

Before we start

We recommend you read the Class instantiation with constructorand Class instantiation with factory method tutorial first.

Important : You should also read Implement the equals method as side effects does an “assert equals” to check the expected and returned value of our SimpleSteps class.

SimpleSteps class

Below is the class that’s used in this test.

The method under test will be addSteps(). This modified the object by modifying the steps properly.

It has a void return type, so we cannot test against the return value. We will need to use a side effect output test.

DevMate configuration

  • First, right-click the addSteps() method an choose Test with DevMate and save the file. It will automatically open up the DevMate editor.

  1. Instantiate a valid instance using the constructor as explained in the Class instantiation with constructor tutorial. This sets the steps property to an initial value of 100.

  2. We will call the addSteps() method with 10. This is explain in Complex arguments tutorial. We're using the SimpleSteps constructor rather than User, of course.

  3. We need to specify an expected output. Because addSteps() returns void, it will create Throws no exception by default when you click the + icon.

  4. Click the + icon next to Side Effects and add a valid equivalence class.

  5. Click the + icon next to valid and a new screen will pop up.

  1. Click the radio button.

  2. We want to edit this value. We initialised SimpleSteps with a value of 100. Our valid Input was 10, so the expected value will be 110. Click the edit button and change the value to 110.

Press Save to return the main editor screen.

Finishing off

  1. You should see your newly defined side effect. Double click to modify, if required.

  2. If DevMate has not pre-load test cases using its Recommendation Engine, press the Generate Test Cases button.

  3. Complete the test case definition as shown.

  4. Press the Generate Test Code button and open the file, once saved.

Running the test

As we have no factory methods to implement, we can now just 1. run the generated test and 2. check it passes.

In the DevMate editor, try changing the side effect value to something other than 110 and it should fail.

Multiple side effects

You can create multiple side effects and, for any given test case, select more than one.