programing

테스트를 찾을 수 없음 - 베어본 Spring Boot Maven 프로젝트에서 jUnit 5 테스트 케이스를 실행할 때 테스트 제품군이 비었습니다.

javajsp 2023. 9. 26. 22:00

테스트를 찾을 수 없음 - 베어본 Spring Boot Maven 프로젝트에서 jUnit 5 테스트 케이스를 실행할 때 테스트 제품군이 비었습니다.

그래서 우리는 메시지를 받았습니다.

Process finished with exit code 0
Empty test suite.

저희 멀티 모듈 프로젝트에서 Junit5 테스트 케이스를 실행하려고 할 때 문제의 출처를 테스트하기 위해 새로운 프로젝트를 처음부터 시도해보기로 했습니다(IntelliJ IDEA 2018.2.4를 사용하고 있습니다).

다음과 같은 간단한 프로젝트 POM 파일에 대해서도 같은 문제가 발생하고 있습니다.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.org.bu.dep.app</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.0.5.RELEASE</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.3.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

저는 주닛 빈티지 엔진과 동일한 결과를 가지고 시도해 보았습니다.

다음은 테스트 클래스입니다.

package com.org.bu.dep.app.demo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class DemoApplicationTests {

    @Test
    public void contextLoads() {
        Assertions.assertTrue(true);
    }

}

실행 창에 다음과 같이 표시됩니다.No tests were found.

여러 가지 변형을 시도했습니다. 위드/위드 등.@SpringBootTest주석, 나는 노력했습니다.@ExtendWith(SpringExtension.class)아무 소용이 없을 뿐만 아니라.

저는 이미 구글링을 했고 대부분의 결과/SackOverflow 답변은 2016/2017년에 Junit 5에 문제가 있었던 IntelliJ의 이전 버전에 초점을 맞춘 것으로 보이는데, 이는 관련이 없는 것 같습니다.

제발, 조언 좀 해주세요.우리가 너무 많은 시간을 소비한다면 어쩔 수 없이 4로 돌아갈 것이고, 저는 그렇게 하고 싶지 않습니다 :)

저 같은 경우에는.private테스트 방법 - 그래야 합니다.public.

Spring Boot 2가 탑재된 Junit 5에서 작동하는 것은 다음과 같은 3가지 TOGETHER입니다.

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.3.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.3.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-params</artifactId>
    <version>5.3.1</version>
    <scope>test</scope>
</dependency>

빈 프로젝트로 테스트하고 검증했습니다.

@Michael Legart의 답변은 다음을 추가할 것을 제안합니다.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.1</version>
</plugin>

테스트를 감지하고 실행하기 위해 메이븐 테스트(및 Jenkins)가 필요합니다!

저한테 효과가 있었던 거죠

추가한 버전을 사용하지 마십시오.junit-bom

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.6.1</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <scope>test</scope>
    </dependency>

와 함께maven-surefire-plugin버전을 추가하지 않음

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

Spring Boot 2가 Junit 5에 필요한 Maven Surefire 플러그인 버전을 사용하지 않기 때문이라고 확신합니다.사용해 보기:

   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.22.1</version>
   </plugin>

JUNIT5 지원은 2.22.0에서 추가되었습니다. https://issues.apache.org/jira/browse/SUREFIRE-1330 참조.

"멍청한" 실수 목록에 제 실수를 추가합니다.잘못 수입했습니다.@Test주석.Junit5는 다음과 같이 주석이 달린 방법만 고려할 것입니다.org.junit.jupiter.api.Test아닌org.junit.Test.

파일 -> 프로젝트 설정 -> 모듈로 이동하여 아래 종속성을 추가합니다.

add dependency

com.github.database-rider:rider-junit 5:1.2.5'를 추가합니다.

enter image description here

com. github. database-rider: rider-junit 5:1.2.5'는 테스트를 찾아 실행합니다.

여러분들이 Intellij를.당신의 것을 표시했습니까?java test folder~하듯이Test Sources Root?

예:

enter image description here

IntelliJ를 사용하여 이 오류를 제거하기 위해 대상 폴더를 삭제하고 테스트를 실행해야 했습니다.

나는 이것이 오래된 질문이라는 것을 알지만 아마도 그것이 누군가에게 도움이 될 것입니다.메서드가 선언된 스크래치 파일에서 메서드를 복사 붙여 넣었기 때문에 오류 메시지가 표시되었습니다.static.

를 들어, 인터페이스나 추상적인 수업에서 시험을 작성하는 경우.

public interface FooTests() {

  @Test
  default void fooTest() {
    ...
  }
}

그 후 "진짜" 테스터 클래스로 구현됩니다.

public class Tester() implements FooTests, BarTests {
  ...
}

그런 중 하여 IntelliJ가 을 , IntelliJ 입니다 로 하게 할 수 있습니다.FooTests::fooTest할 때는Tester::fooTest. 테스트의 실행 구성을 수정하여 이를 재정의할 수 있습니다.

enter image description here

Method: 클래스를 non-interface, non-abstract test runner 클래스로 바꾸려고 합니다.

언급URL : https://stackoverflow.com/questions/53179735/no-tests-were-found-empty-test-suite-when-running-junit-5-testcase-on-bare-bon