Next page | Contents page |

Exercise 30 - IntegerTest

Write a JUnit 4 test class with a method that tests the compareTo() method of java.lang.Integer.

Then add another test method for Integer.parseInt(). How should you test that the exception that the method under test could throw is really thrown in the right circumstances? (A test that passes when the exception is thrown.)

Make sure you see some tests fail during this exercise, and examine what happens.

In reality we would trust 3rd party APIs and not unit test them.

Next page | Contents page |