Maven의 테스트 명령으로 JUnit5 테스트를 실행할 수없는 경우의 조치

현상



이쪽의 졸 기사 에서 RESTfulAPI의 Unit 테스트를 만들었습니다.
IntelliJ상에서의 실행은 문제 없었다.

그러나 명령 mvn test 그러면 테스트가 비어 있습니다.
$ mvn clean test
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

이것은 곤란했다. 최종적으로는 CI툴로 움직이는 것이 목적이기 때문이다.

그렇다고 해서, 굉장히 뛰었습니다.

참고 페이지



  • JUnit Setup Maven – JUnit 4 and JUnit 5
    htps //w w. r.l에서 v. 코 m / 21711 / 쥬니 t 세츠 p ゔ
  • JUnit4와 5의 차이를 명기하고 있어 알기 쉬웠다.
  • 그리고 아마, additionalClasspathElements 가 필요했던 것 같다.
  • 왜냐하면, 테스트 클래스는 src/test/java/ 아래에 두고 있었기 때문에. (왜 기본적으로 볼 수 없습니까?)


  • JUnit 5 사용자 가이드의 일본어 번역
    htps : // 우즈키. jp / 푸 b c / 쥬니 t5 - 우세 r - 글로 - /
  • 특히, 2.3. JUnit Jupiter 샘플 프로젝트의 섹션에 있는 샘플 프로젝트가 참고가 되었습니다.


  • 결론



    마지막으로 pom.xml 를 다음과 같이 하여 무사, 명령으로도 통과하게 되었습니다.
    (IntelliJ에서 실행하는 데 문제가 없습니다)
    어쩌면 불필요한 것도있을 수 있습니다.

    2020/03/13 추가
    불필요하다고 밝혀진, 이하 2개의 의존 기술에 대해서, 삭제했습니다.
    - junit-platform-surefire-provider
    - junit-platform-runner

    pom.xml
    <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/maven-v4_0_0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.example</groupId>
        <artifactId>simple-webapp</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>simple-webapp</name>
    
        <build>
            <finalName>simple-webapp</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <inherited>true</inherited>
                    <configuration>
                        <source>11</source> <!-- ここ -->
                        <target>11</target> <!-- ここ -->
                </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.2</version>
                    <configuration>
                        <additionalClasspathElements>
                            <additionalClasspathElement>src/test/java/</additionalClasspathElement>
                        </additionalClasspathElements>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.jersey</groupId>
                    <artifactId>jersey-bom</artifactId>
                    <version>${jersey.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey.containers</groupId>
                <artifactId>jersey-container-servlet-core</artifactId>
                <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
                <!-- artifactId>jersey-container-servlet</artifactId -->
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.inject</groupId>
                <artifactId>jersey-hk2</artifactId>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.media</groupId>
                <artifactId>jersey-media-json-binding</artifactId>
                <version>${jersey.version}</version>
            </dependency>
            <!-- JAXBはJDK9から外されました -->
            <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.3.1</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
            <dependency>
                <groupId>javax.activation</groupId>
                <artifactId>activation</artifactId>
                <version>1.1.1</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
            <dependency>
                <groupId>org.glassfish.jaxb</groupId>
                <artifactId>jaxb-runtime</artifactId>
                <version>2.3.2</version>
            </dependency>
    
            <!-- テスト -->
            <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>${junit.jupiter.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>${junit.jupiter.version}</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.test-framework.providers/jersey-test-framework-provider-grizzly2 -->
            <dependency>
                <groupId>org.glassfish.jersey.test-framework.providers</groupId>
                <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
                <version>2.30.1</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
            <dependency>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
                <version>3.15.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-params</artifactId>
                <version>${junit.jupiter.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <properties>
            <jersey.version>2.30.1</jersey.version>
            <junit.jupiter.version>5.6.0</junit.jupiter.version>
            <junit.platform.version>1.3.2</junit.platform.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    </project>
    

    이제
    $ mvn clean test
    
    (省略)
    [INFO] 
    [INFO] Results:
    [INFO] 
    [INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
    [INFO] 
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  5.524 s
    [INFO] Finished at: 2020-03-11T00:01:17+09:00
    [INFO] ------------------------------------------------------------------------
    

    했어!

    결과를 HTML로 내보내기



    어차피라면 테스트 결과를 보기 쉽게 하려고 하고, 아래의 페이지를 참고로 설정했습니다.
  • Maven에서 JUnit 테스트 보고서 출력
    htps : // 이 m / 푹신한 d / ms / b10d4597d62, 1b3, 94

  • pom에 <report> 태그를 쓰는 방법의 소개도 몇개인가 있었지만, 그 방법으로는 할 수 없었습니다・・・

    위의 페이지대로 pom.xml에 덧붙여 위의 페이지대로 명령을 실행하면 아래 그림과 같은 html이 작성되었습니다.






    Gradle의 내보내는 리포트에 익숙해져 있기 때문에, 조금 보기 어렵다・・・(땀)
    Gradle이라면 특별한 설정은 불필요하고 html도 토해주는데.
    Gradle이라면・・・(어른의 사정에 눈물)

    현장에서는 이상입니다.

    좋은 웹페이지 즐겨찾기