When programming Eclispe, Junit is often used for unit testing. There are two ways to test a single unit.

  • Write a test class, then write two test methods. Such as:
package com.tools;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestAoction {
	
	@BeforeAll
	public static void testInit(a) {
		System.out.println("Data initialization...");
	}
	@BeforeEach
	private void testBeforEach(a) {
		System.out.println("Execute before executing the unit test method...");
	}
	@AfterEach
	public void testfterEach(a) {
		System.out.println("Execute after executing the unit test method...");
	}
	@Test
	public void test1(a) {
		System.out.println("Unit Test Method 1...");
	}
	@Test
	public void test2(a) {
		System.out.println("Unit Test Method 2..."); }}Copy the code
  • Method 1: Right-click the method name and choose Run AS – > Junit Test from the shortcut menu

  • Method 2: Expand the method on the left, select Test method, and right-click Run As -> Junit Test.

  • If you’re running the entire test class, you can test all of the test classes in that class by right clicking in the blank or by selecting the class