No tests found in TestClass Haven’t you forgot @Test annotation?
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.
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.
You could refactor MyClass so that it uses dependency injection. Instead of having it create an AnythingPerformerClass instance you could pass in an instance of the class to the constructor of MyClass like so : class MyClass { private final AnythingPerformerClass clazz; MyClass(AnythingPerformerClass clazz) { this.clazz = clazz; } public boolean performAnything() { return clazz.doSomething(); … Read more
In JUnit 5 (from version 5.8.0 onwards) test classes can be ordered too. src/test/resources/junit-platform.properties: # ClassOrderer$OrderAnnotation sorts classes based on their @Order annotation junit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer$OrderAnnotation Other Junit built-in class orderer implementations: org.junit.jupiter.api.ClassOrderer$ClassName org.junit.jupiter.api.ClassOrderer$DisplayName org.junit.jupiter.api.ClassOrderer$Random For other ways to set configuration parameters (beside junit-platform.properties file) see JUnit 5 user guide. You can also provide your own orderer. … Read more
A solution to the first issue is to move the logic into an extension of org.junit.rules.ExternalResource hooked up to the test via a @ClassRule, introduced in JUnit 4.9: public class MyTest { @ClassRule public static final TestResources res = new TestResources(); @Test public void testFoo() { // test logic here } } public class TestResources … Read more
if you do a employee = new Employee(param1, param2); you may as well skip @InjectMocks. It is supposed to do the following: @InjectMocks ClassUnderTest cut; @Mock Dependency1 dep1; @Mock Dependency2 dep2; @Before public void setup() { initMocks(this); } omitting @InjectMocks the same behaviour can be achieved with the following code: ClassUnderTest cut; @Mock Dependency1 dep1; … Read more
Though it does not really solve your immediate problem, I find it a very useful general practice to create suites and suites of suites, e.g. for a package something like PackageFooSuite etc. and assemble these suites in one or more suites again, like ModuleFooSuite and have one top-level suite, like AllTestsSuite. That way it’s easy … Read more
I also stumbled upon this issue today. It seems that eclipse uses the JUnit 5 runner by default if JUnit 5 dependencies are found on the classpath. In case of my maven project, investigating the dependency hierarchy showed that actually both JUnit 4 and JUnit 5 dependencies were on the classpath. JUnit 4 as the … Read more