Skip to content

Getting started

kcooney edited this page Sep 4, 2012 · 4 revisions

Getting Started

Note: This is very much a work in progress.

Creating a New Test Case

Here is a template for writing JUnit4-style tests:


import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

 * Tests for {@link Foo}.
 * @author (John Doe)
public class FooTest {

  public void thisAlwaysPasses() {

  public void thisIsIgnored() {


  • All test methods are annotated with @Test. Unlike JUnit3 tests, you do not need to prefix the method name with "test" (and usually don't)
  • Do not have your test classes extend junit.framework.TestCase (directly or indirectly). Usually, tests with JUnit4 do not need to extend anything (which is good, since Java does not support multiple inheritance)
  • Do not use any classes in junit.framework or junit.extensions
Something went wrong with that request. Please try again.