Search code examples
spring-bootunit-testingspring-boot-test

A simple unit test, when run it, get error "No tests found"


In my springboot project, I don't need to unit test those mvc things but some pure POJO classes.

My pojo class:

public class Calculator {

   public int add(int a, int b) {
       return a+b;
   }
}

My test class:

@ExtendWith(SpringExtension.class)
public class SimpleTest {
    @Test
    void testIt() {
      Calculator cal = new Calculator();
      int result = cal.add(1, 2);
      assertThat(result).isEqualTo(3);
    }
}

I am using intellij IDE. Next to the void testIt() line of code on the left, there is a small run arrow, when I click and run the test function , I get failure:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [com.my.calculator.SimpleTest.testIt](filter.includeTestsMatching)

Why I get this No test found error?

BTW, the dependencies of my project for the test :

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.assertj:assertj-core'

Solution

  • can you check if you have this following part:

    test {
        useJUnitPlatform()
    }