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?
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?
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.
The method needs to be explicitly declared as public
:
@Test
public void asdf() {
asdf...
}
Import junit package in stead of testng package.
If you've upgraded to Junit 5, according to this How to use Mockito with JUnit5:
"No Rules, No Runners JUnit 4 rules and runners don't work in JUnit 5, so the MockitoRule and the Mockito runner can not be used."
Use @ExtendWith(MockitoExtension.class) instead. Verified this on Junit 5.6.2 and Spring boot 2.3.1:
@ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) public class ClassTest {}
Don't also forget to explicitly declare the test method as public as well.
Just remove the public access modifier from the test class and go with the
import org.junit.jupiter.api.Test;
you need to check the import of the test in the class for example from :import org.junit.jupiter.api.Test;
into: import org.junit.Test;