JUnit 4.x in Eclipse, a Quick Tutorial

9 downloads 398 Views 254KB Size Report
28 Nov 2008 ... This tutorial is for a bit more experienced Java programmers. ... you are an Eclipse user; so you would know e.g. how to add a jar to your ...
JUnit 4.x in Eclipse, a Quick Tutorial Wishnu Prasetya November 28, 2008 This tutorial is for a bit more experienced Java programmers. I will assume: • you know how to write JUnit tests (else see e.g. my JUnit 4.x Quick Tutorial). • you are an Eclipse user; so you would know e.g. how to add a jar to your project’s build path.

Setting up an example Start a new project first; call it e.g. MyProject. Create in this project the following java class (which should be called Subscription.java). This will be the class we are going to test. public class Subscription { private int price ; // subscription total price in euro-cent private int length ; // length of subscription in months /** * A constructor to create a subsription. */ public Subscription(int p, int n) { price = p ; length = n ; } /** * Calculate the monthly subscription price in euro, * rounded up to the nearest cent. */ public double pricePerMonth() { if (length