Site icon TestingDocs.com

Anatomy of a JUnit Test

Anatomy of a JUnit Test

A typical JUnit 4 test would look like as shown:

 

Sample JUnit 4 Test

package car;

import static org.junit.Assert.*;
import org.junit.Test;

public class CarTest {

  @Test
  public void testCar() {
    assertTrue(true); 
  }

  @Test
  public void testGetIsSedan() {
    assertTrue(true); 
  }

  @Test
  public void testGetSeats() {
    fail("Not yet implemented"); // TODO
  }

  @Test
  public void testGetMileage() {
    fail("Not yet implemented"); // TODO
  }

}

Adding JUnit 4 library

Click on the Error. Select Quick Fix >> Fix Project Setup…

Add Junit 4 library to the build path

 

 

JUnit Tutorial: https://www.testingdocs.com/junit-tutorial/

More information on JUnit can be found on the official website: https://junit.org

Exit mobile version