This is a simple tutorial to show how DevMate works with generics

Github

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

The method

Here is the simplest method we could come up with. Let us know if we can make it simpler!

  • Right click on the isEqual() method name to generate a test with DevMate.

Configuring <T>

We’ll start out by instantiating GenereicDemo (we didn't use a static class this time).

  1. Create a valid representative (click the + icon and select GenericDemo from the initializer dropdown).

  2. Make sure you click on the method cell as shown.

  3. Click the Properties button to open up the panel on the right (the properties won’t appear until you do).

  4. You can see the Types dropdown. Choose a type from the dropdown - why not choose an int type? You’ll notice that the <T> has now been replaced by <int>. You can close the properties panel now if you like.

Configuring inputs and outputs

Let’s set up some a simple valid and invalid test.

  1. Let’s create a valid equivalence class value of 100 for g1.

  2. And 100 for g2 (they need to be the same as it's testing equality.

  3. We’ll create an invalid equivalence class with value 101 (so equality fails).

  4. The valid output equivalence class return true

  5. And the invalid, false.

And with that, you can press Generate Test Code and run your test.