Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse keep saying "No tests found with test runner JUnit 5"

I am using Eclipse Oxygen.3 Release (4.7.3). The following is my JUnit test class:

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

class MyMathTest {
    MyMath myMath = new MyMath();

    @Before
    public void before() {
        System.out.println("Before");
    }

    @After
    public void after() {
        System.out.println("After");
    }

    @Test
    public void testSum_with3numbers() {
        System.out.println("Test1");
        int result = myMath.sum(new int[] {1,2,3});
        int expected = 6;
        assertEquals(expected, result);
    }

    @Test
    public void testSum_with1numbers() {
        System.out.println("Test2");
        int result = myMath.sum(new int[] {3});
        int expected = 3;
        assertEquals(expected, result);
    }

    @BeforeClass
    public static void beforeClass() {
        System.out.println("Before class");
    }

    @AfterClass
    public static void afterClass() {
        System.out.println("After class");
    }

}

When I run this Junit test, eclipse keeps popping up dialog telling "No tests found with test runner 'JUnit 5'". Why?

enter image description here

like image 308
Leem Avatar asked May 01 '18 15:05

Leem


2 Answers

the test class is not public, make it public and it should work

like image 111
Karsankaka Avatar answered Oct 20 '22 21:10

Karsankaka


This happened to me because my test method was declared as private and JUnit could not detect it. After I made it public it worked as expected, of course with @Test annotation.

like image 22
Cosmin Mavrichi Avatar answered Oct 20 '22 20:10

Cosmin Mavrichi