Lesson 15 - Activity 1 - Can you create a test that checks for an exception?

Time: 15 minutes

Purpose: This activity helps you get familiar with thrown exceptions

Introduction: You’re had experience using a assertions, now create one for checking for thrown exceptions

Task: public static int parseInt(String s) throws NumberFormatException if it can’t convert to int

Create,

  1. A JUnit test where a string is successfully converted int
  2. A JUnit tests which checks for an exception is thrown