Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No tests found in TestClass Haven't you forgot @Test annotation?

I am getting an error like this when running my test:

org.mockito.exceptions.base.MockitoException: 

No tests found in TestCase
Haven't you forgot @Test annotation?

I certainly do have a method annotated with @Test. What am I doing wrong?

like image 851
Babken Vardanyan Avatar asked May 13 '15 08:05

Babken Vardanyan


People also ask

What is the @test annotation?

The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure.

How do you resolve Testng no tests found nothing was run?

Solution. The easiest solution would be to change the @BeforeTest annotation with @Test and execute you Test case / Test Suite.

What is the use of @test annotation in JUnit?

The @Test annotation is used to identify the actual test case. This is required as JUnit allows multiple tests to be grouped under a single test class. The test method is where assertions are done and the result is determined.

What is the purpose of the following annotation at test?

@Test annotation tells JUnit that this public void method (Test Case here) to which it is attached can be run as a test case.


3 Answers

The method needs to be explicitly declared as public:

@Test
public void asdf() {
    asdf...
}
like image 183
Babken Vardanyan Avatar answered Oct 01 '22 01:10

Babken Vardanyan


I got this exception even though I had a public method annotaded with @Test. Turned out was importing org.junit.jupiter.api.Test, I changed to org.junit.Test and it worked fine.

like image 54
Jefferson Lima Avatar answered Oct 01 '22 01:10

Jefferson Lima


Import junit package in stead of testng package.

like image 8
Bingo Avatar answered Oct 01 '22 03:10

Bingo