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.
- Create a new Java project called
com.packtpub.e4.junit.example
. - Create a class called
MathUtil
incom.packtpub.e4.junit.example
. - Create a
public static
method calledisOdd
that takes anint
and returns aboolean
if it is an odd number (usingvalue % 2 == 1
). - Create a new class called
MathUtilTest
in a packagecom.packtpub.e4.junit.example
. - Create a method called
testOdd
with an annotation@Test
, which is the way JUnit 4 signifies that this method is a test case. - 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
. - 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.