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?
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.
Solution. The easiest solution would be to change the @BeforeTest annotation with @Test and execute you Test case / Test Suite.
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.
@Test annotation tells JUnit that this public void method (Test Case here) to which it is attached can be run as a test case.
The method needs to be explicitly declared as public
:
@Test
public void asdf() {
asdf...
}
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.
Import junit package in stead of testng package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With