2 Minutes To Code (β Version)

JUnit 3.10 - 2 minute tutorial

How to test a class

The example below shows how to write and run test cases.

First of all, create a class as a subclass of junit.framework.TestCase. Then begin all methods names that you want junit to run as tests with the string "test".

To run the test cases, use the run() method of class junit.textui.TestRunner with the class name containing test methods as argument as shown in the main() method below.

The crux of junit functionality is provided by the method calls assertEquals and assertTrue below which are inherited through the superclass TestCase.

The list of such methods provided by TestCase class are assertTrue, assertFalse, assertEquals, assertSame, assertNotSame, assertNull, assertNotNull, and fail.
package com.techfundaes.junit3_8_1;

import junit.framework.TestCase;
import junit.textui.TestRunner;

public class TestBasic extends TestCase
	public void testTransact()
		Account account = new Account();
		assertTrue(account.balanceAmount == 50);
	public void testTransactObject()
		Account accountOne = new Account();
		Account accountTwo = new Account();
		assertEquals(200, accountOne.balanceAmount);
	public static void main(String[] args)