Time for action – writing a simple JUnit 4 test case

This part explains how to write and run a simple JUnit 4 test case in Eclipse.

  1. Create a new Java project called com.packtpub.e4.junit.example.
  2. Create a class called MathUtil in com.packtpub.e4.junit.example.
  3. Create a public static method called isOdd that takes an int and returns a boolean if it is an odd number (using value % 2 == 1).
  4. Create a new class called MathUtilTest in a package com.packtpub.e4.junit.example.
  5. Create a method called testOdd with an annotation @Test, which is the way JUnit 4 signifies that this method is a test case.
  6. Click on the quick-fix to Add JUnit 4 library to the build path, or edit the build path manually to point to Eclipse's plugins/org.junit_4.*.jar.
  7. Implement the ...

Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.