programing

Maven이 실행할 JUnit 테스트를 찾을 수 없습니다.

sourcejob 2022. 8. 12. 23:11
반응형

Maven이 실행할 JUnit 테스트를 찾을 수 없습니다.

난 메이븐 프로그램을 가지고 있어. 컴파일은 잘 돼.★★★★★★★★★★★★★★★를 실행했을 때,mvn test에 "TESTS"로 표시됩니다(TESTS는 "TESTS"로 표시됩니다).There are no tests to run.

를 재현한 은, , ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★이 설정에는, 이하와 함께 실행했을 경우의 출력도 포함됩니다.-X.

유닛 테스트는 이클립스부터 정상적으로 실행됩니다(디폴트 junit 패키지와 함께, 대신 maven에 의해 다운로드된 junit.jar를 포함했을 때). 한 mv mvn도test-compile는 테스트 테스트 대상 클래스를 올바르게 만듭니다.Maven 3.0.2' Java 1.6.0_24' OSX 10.6.7에서 실행하고 있습니다.

디렉토리 구조는 다음과 같습니다.

/my_program/pom.xml
/my_program/src/main/java/ClassUnderTest.java
/my_program/src/test/java/ClassUnderTestTests.java

pom.xml:

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my_group</groupId>
    <artifactId>my_program</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>My Program</name>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Class Under Test.java:

public class ClassUnderTest {

    public int functionUnderTest(int n) {
        return n;
    }

}

Class Under Tests.java:

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ClassUnderTestTests {

    private ClassUnderTest o;

    @Before
    public void setUp() {
        o = new ClassUnderTest();
    }

    @Test
    public void testFunctionUnderTest_testCase1() {
        Assert.assertEquals(1, o.functionUnderTest(1));
    }

    @Test
    public void testFunctionUnderTest_testCase2() {
        Assert.assertEquals(2, o.functionUnderTest(2));
    }
}

mvn - X 테스트 종료:

[DEBUG] Configuring mojo org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-surefire-plugin:2.7.1, parent: sun.misc.Launcher$AppClassLoader@5224ee]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test' with basic configurator -->
[DEBUG]   (s) basedir = /Users/aaron/Programs/my_program
[DEBUG]   (s) childDelegation = false
[DEBUG]   (s) classesDirectory = /Users/aaron/Programs/my_program/target/classes
[DEBUG]   (s) disableXmlReport = false
[DEBUG]   (s) enableAssertions = true
[DEBUG]   (s) forkMode = once
[DEBUG]   (s) junitArtifactName = junit:junit
[DEBUG]   (s) localRepository =        id: local
      url: file:///Users/aaron/.m2/repository/
   layout: none

[DEBUG]   (f) parallelMavenExecution = false
[DEBUG]   (s) pluginArtifactMap = {org.apache.maven.plugins:maven-surefire-plugin=org.apache.maven.plugins:maven-surefire-plugin:maven-plugin:2.7.1:, org.apache.maven.surefire:surefire-booter=org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile, org.apache.maven.surefire:surefire-api=org.apache.maven.surefire:surefire-api:jar:2.7.1:compile, org.apache.maven.surefire:maven-surefire-common=org.apache.maven.surefire:maven-surefire-common:jar:2.7.1:compile, org.apache.maven.shared:maven-common-artifact-filters=org.apache.maven.shared:maven-common-artifact-filters:jar:1.3:compile, org.codehaus.plexus:plexus-utils=org.codehaus.plexus:plexus-utils:jar:2.0.5:compile, junit:junit=junit:junit:jar:3.8.1:compile, org.apache.maven.reporting:maven-reporting-api=org.apache.maven.reporting:maven-reporting-api:jar:2.0.9:compile}
[DEBUG]   (s) printSummary = true
[DEBUG]   (s) project = MavenProject: my_group:my_program:1.0-SNAPSHOT @ /Users/aaron/Programs/my_program/pom.xml
[DEBUG]   (s) projectArtifactMap = {junit:junit=junit:junit:jar:4.8.1:test}
[DEBUG]   (s) redirectTestOutputToFile = false
[DEBUG]   (s) remoteRepositories = [       id: central
      url: http://repo1.maven.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => never]
]
[DEBUG]   (s) reportFormat = brief
[DEBUG]   (s) reportsDirectory = /Users/aaron/Programs/my_program/target/surefire-reports
[DEBUG]   (s) session = org.apache.maven.execution.MavenSession@dfbb43
[DEBUG]   (s) skip = false
[DEBUG]   (s) skipTests = false
[DEBUG]   (s) testClassesDirectory = /Users/aaron/Programs/my_program/target/test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG]   (s) testNGArtifactName = org.testng:testng
[DEBUG]   (s) testSourceDirectory = /Users/aaron/Programs/my_program/src/test/java
[DEBUG]   (s) trimStackTrace = true
[DEBUG]   (s) useFile = true
[DEBUG]   (s) useManifestOnlyJar = true
[DEBUG]   (s) workingDirectory = /Users/aaron/Programs/my_program
[DEBUG] -- end configuration --
[INFO] Surefire report directory: /Users/aaron/Programs/my_program/target/surefire-reports
[DEBUG] Setting system property [user.dir]=[/Users/aaron/Programs/my_program]
[DEBUG] Setting system property [localRepository]=[/Users/aaron/.m2/repository]
[DEBUG] Setting system property [basedir]=[/Users/aaron/Programs/my_program]
[DEBUG] Using JVM: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile (selected for compile)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:compile (selected for compile)
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-booter/2.7.1/surefire-booter-2.7.1.jar Scope: compile
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: compile
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-junit4:jar:2.7.1:test (selected for test)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:test (selected for test)
[DEBUG] Adding to surefire test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-junit4/2.7.1/surefire-junit4-2.7.1.jar Scope: test
[DEBUG] Adding to surefire test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: test
[DEBUG] Test Classpath :
[DEBUG]   /Users/aaron/Programs/my_program/target/test-classes
[DEBUG]   /Users/aaron/Programs/my_program/target/classes
[DEBUG]   /Users/aaron/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile (selected for compile)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:compile (selected for compile)
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-booter/2.7.1/surefire-booter-2.7.1.jar Scope: compile
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: compile
Forking command line: /bin/sh -c cd /Users/aaron/Programs/my_program && /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar /Users/aaron/Programs/my_program/target/surefire/surefirebooter6118081963679415631.jar /Users/aaron/Programs/my_program/target/surefire/surefire4887918564882595612tmp /Users/aaron/Programs/my_program/target/surefire/surefire9012255138269731406tmp

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.089s
[INFO] Finished at: Mon May 30 12:03:09 EDT 2011
[INFO] Final Memory: 7M/62M
[INFO] ------------------------------------------------------------------------

기본적으로 Maven은 실행할 테스트를 검색할 때 다음과 같은 명명 규칙을 사용합니다.

사용 중인 테스트 클래스가 이러한 규칙을 따르지 않는 경우 테스트 클래스에 다른 패턴을 사용하도록 이름을 변경하거나 Maven Surefire 플러그인을 구성해야 합니다.

또한 유닛 테스트코드가 다음 코드 아래에 있어야 한다는 것도 발견했습니다.src/test/java폴더는 메인 폴더 아래에 두면 테스트 클래스로 인식되지 않습니다.§:

틀렸어

/my_program/src/main/java/NotTest.java

맞다

/my_program/src/test/java/MyTest.java

갱신:

Maven Surefire 2.22.0부터는 @scottyseus가 코멘트에서 말한 것처럼 다음과 같이 충분합니다.

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

JUnit 5는 JUnit 5로 되어 있습니다.Maven Surefire JUnit 5 。을 우리 '아까보다'에 더해보세요.pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0-M1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.2.0-M1</version>
        </dependency>
    </dependencies>
</plugin>

출처 : https://junit.org/junit5/docs/current/user-guide/ #running-moven-build-maven

갱신 2021

JUnit 팀이 개발한 junit-platform-surefire-provider는 JUnit Platform 1.3에서 폐지되었으며 1.4에서 단종되었습니다.대신 Maven Surefire의 네이티브 지원을 사용하십시오.

모듈 패키징이 올바르게 선언되지 않으면 Maven이 테스트를 찾을 수 없는 또 다른 원인이 될 수 있습니다.

최근 사건에서, 누군가가<packaging>pom</packaging>그리고 내 테스트는 실행되지 않았다.는 그것을 ㅇㅇㅇㅇㅇㅇㅇ로 요.<packaging>jar</packaging>이제 잘 작동하게 되었습니다.

제 경우 Junit-vintage-engine을 추가하여 이전 버전의 JUnit 테스트와 호환되며 실행할 수 있습니다.JUnit 5를 쓰니까.

<dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
</dependency>

Spring BootSpring Initializr를 사용한 어플리케이션.Intelij Idea에서 테스트는 정상적으로 실행됩니다.단, 명령줄에서 테스트를 실행하려는 경우:

mvn clean test

테스트가 전혀 실행되지 않아서 놀라셨을 수도 있습니다.surefire plugin은 간단했다. 즉, '아주 좋다'였다.pom.xml에는 다음과 같은 의존관계가 포함되어 있습니다.

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
           <exclusion>
              <groupId>org.junit.vintage</groupId>
              <artifactId>junit-vintage-engine</artifactId>
           </exclusion>
        </exclusions>
     </dependency>

외,는junit-vintage-engine 、 , , , , with with with with withibilityibilityibilityibilityibilityibilityibilityibilityibilityibilityibilityibilityibilityibilityibility , , , ,와의 하위 호환성을 하기 위한 입니다.JUnit 4.xSpring Boot Initializr, Spring Boot Initializr, Spring Boot Initializr, Spring Boot Initializr.후, 「 」는 「 」로 되어 있습니다.Maven프로젝트의 테스트를 보기 시작했습니다.

클래스 java)가 속성 「」에 되고 있는 하고 있는지 .<testSourceDirectory>".xml" 아래에 pom<build> ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

이러한 답변의 대부분은 과거에 매우 유용했지만, 향후 다른 사람에게 도움이 될 수 있기 때문에 시간이 걸린 시나리오를 추가하고 싶습니다.

테스트 클래스 및 메서드가 공개되어 있는지 확인합니다.

문제는 IDE(IntelliJ)의 자동 테스트 클래스/메서드 생성 기능을 사용하고 있었는데, 어떤 이유로 패키지 전용으로 생성되었다는 것입니다.나는 이것이 생각보다 놓치기 쉽다는 것을 알았다.

나는 이 문제와 씨름하고 있다.내 경우 올바른 @Test 주석을 가져오지 않았습니다.

1) @Test가 org.junit의 것인지 확인합니다.jupiter.api를 클릭합니다.테스트(Junit 5를 사용하는 경우)

Junit5가 하는 @RunWith(SpringRunner.class)하다, 사용하다@ExtendWith(SpringExtension.class)

import org.junit.jupiter.api.Test;

@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
@TestPropertySource(locations = "classpath:application.properties")    
public class CotacaoTest {
    @Test
    public void testXXX() {

    }
}

프로젝트가 다음과 같은 경우 Maven은 테스트를 수행하지 않습니다.<packaging>pom</packaging>

를 jar java 유형.java artefact ( java artefact ) 。<packaging>jar</packaging>

테스트 앞에 '추상'을 붙이면 기본적으로 무시됩니다.

그것을 확인합니다(jUnit - 4.12 및 Eclipse surefire 플러그인의 경우).

  1. 의존관계에 필요한 jUnit 버전을 POM.xml에 추가합니다.Maven - > 프로젝트를 업데이트하여 프로젝트에서 내보낸 필수 항아리를 확인합니다.
  2. 테스트 클래스는 이 폴더의 src/test/java 폴더와 서브 디렉토리 아래에 있습니다(또는 config testSourceDirectory의 POM에서 기본 폴더를 지정할 수 있습니다).클래스 이름에는 'Test'라는 단어가 붙어야 합니다.
  3. 테스트 클래스의 테스트 메서드에는 @Test 주석이 있어야 합니다.

Junit 5에서 팔로잉은 나에게 잘 먹혔다.

https://junit.org/junit5/docs/current/user-guide/ #running-moven-build-maven

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
    </plugins>
</build>
<!-- ... -->
<dependencies>
    <!-- ... -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
    <!-- ... -->
</dependencies>
<!-- ... -->

저도 비슷한 문제가 있었는데, 조사한 결과 testng 의존성이 이 문제의 원인입니다.pom에서 testng 의존성을 제거한 후(필요가 없어졌기 때문에) 정상적으로 동작하기 시작했습니다.

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8</version>
        <scope>test</scope>
    </dependency>

제 경우 멀티 모듈애플리케이션을 Spring Boot로 이행하고 있습니다.안타깝게도 maven은 모듈의 모든 테스트를 더 이상 수행하지 않았습니다.테스트 클래스의 이름은 변경되지 않았으며 명명 규칙을 따르고 있습니다.

에 내가 를 더하면이 되었다.surefire-junit47합니다.maven-surefire-plugin하지만 왜 시행착오인지 설명할 수 없었다.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
  <dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-junit47</artifactId>
    <version>${maven-surefire-plugin.version}</version>
  </dependency>
</dependencies>

Maven Surefire 플러그인은 몇 가지 테스트 프레임워크를 지원합니다.사용하고 있는 프레임워크를 자동 검출하고, 그 프레임워크를 사용해 작성된 테스트를 검색합니다.자동검출이 혼동되어 잘못된 프레임워크를 선택하면 두 번째 단계에서는 테스트를 찾을 수 없습니다.

자동검출은 클래스 패스에서 지원하는 테스트 프레임워크에 대해 중요한 "드라이버" 클래스가 존재하는지 검사하여 작동합니다.따라서 POM 또는 모듈에 의존하는 POM이 이러한 "드라이버" 클래스 중 하나에 잘못 종속되어 있는 경우 자동검출이 잘못될 수 있습니다.

현시점(2020년)에서는 JUnit 4와 JUnit 5의 차이에 특별한 문제가 있습니다.Surefire 플러그인은 이들을 다른 프레임워크로 취급합니다.그러나 패키지 이름이 비슷하기 때문에 프로젝트는 잘못된 프레임워크에 의존할 수 있지만 일상적인 검사에는 문제가 없는 것으로 보입니다.

하세요.junit-platform-console지만 JUnit 5용입니다.junit-platform-runnerJUnit 4 입 ju ju ju프로젝트가 후자에 의존할 경우 Surefire는 JUnit 5 테스트를 실행하지 않습니다.

공유 Java/Groovy 어플리케이션이 있고 Groovy 유닛 테스트만 있다면 Maven은 테스트를 찾을 수 없습니다.이 문제는 src/test/java 아래에 1개의 단위 테스트를 추가하여 해결할 수 있습니다.

/my_program/src/test/java/ClassUnderTestTests.java

그래야 한다

/my_program/src/test/java/ClassUnderTestTest.java

Maven은 자동으로 실행되도록 테스트 또는 테스트로 시작하는 끝 부분을 찾습니다.

단,

mvn surefire:test -Dtest=ClassUnderTestTests.java 

테스트를 실행할 수 있습니다.

다음은 pom.xml에 추가해야 하는 정확한 코드입니다.

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.2.0-M1</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.2.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

제 의존관계는 다음과 같습니다.

    <dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.easytesting</groupId>
        <artifactId>fest-assert-core</artifactId>
        <version>2.0M10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-surefire-provider</artifactId>
        <version>1.2.0-M1</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.2.0-M1</version>
    </dependency>
</dependencies>

같은 문제에 직면했는데, pom.xml을 아래와 같이 변경함으로써 해결되었습니다.

<build>
    <testSourceDirectory>test</testSourceDirectory>

...

변경 내용:

<build>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>

이 표준 않는 표시됨)에.pom.xml -Maven을하려면 -Maven을 선택합니다.

...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <includes>
                    <include>**/*_UT.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build> 
...

아마 흔한 실수는 아니지만 @Joang Matos의 답변에 더해서.메서드를 공개해야 하는 요건 외에 다음과 같은 것이 있습니다.

희희 be be you you you you you you you you 。void '아예'도 @Test석입니니다다

이렇게 하면 안 돼요.

@Test
public Integer fooBarTest() {
   // omitted
}

해야 합니다.void:

@Test
public void fooBarTest() {
   // omitted
}

한 가지 팁(이전 답변 외에):

Eclipse에서 으로 이동> [ Eclipse 을 클릭합니다.Run/Debug Settings

"이 페이지에서는 현재 선택한 리소스로 부팅 구성을 관리할 수 있습니다."

삭제 수 ((JUnit)에서).src/test/java을 사용하다

내 경우엔, 우리 부모님 폼은 부모님이 계셔.

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

spring pom Import로 변경한 후:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>some version</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

유닛 테스트가 시작되었습니다.

테스트 케이스를 실행하지 않은 또 다른 이유는 전혀 다른 목적으로 "test"라는 속성을 사용했는데 Surefire 플러그인에 방해가 되었습니다.따라서 POM에서 다음 사항을 확인하십시오.

<properties>
  <test>.... </test>
  ...
</properties>

제거해 주세요.

JUnit 4에서 테스트를 작성하고 Surefire 플러그인에 JUnit 5 종속성을 추가한 경우 테스트가 실행되지 않습니다.

이 경우 surefire 플러그인에서 JUnit 5 종속성을 코멘트합니다.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <!--<dependencies>-->
                <!--<dependency>-->
                    <!--<groupId>org.junit.platform</groupId>-->
                    <!--<artifactId>junit-platform-surefire-provider</artifactId>-->
                    <!--<version>1.0.0</version>-->
                <!--</dependency>-->
                <!--<dependency>-->
                    <!--<groupId>org.junit.jupiter</groupId>-->
                    <!--<artifactId>junit-jupiter-engine</artifactId>-->
                    <!--<version>${junit.version}</version>-->
                <!--</dependency>-->
            <!--</dependencies>-->
        </plugin>

3.로 Surfire 3.x.x+ JUnit5로 주석을 붙였을 때 할 수 .@TestJUnit4는 JUnit4입니다.

: ★★★★org.junit.jupiter.api.TestJUnit5)가 (org.junit.Test (Junit4)

메모: 이 문제는 JUnit4 테스트와 마찬가지로 IDE에서 실행될 수 있기 때문에 알아차리기 어려울 수 있습니다.

최근에 경험한 또 다른 문제인 테스트 클래스 파일의 확장자가 .java 인 것을 확인합니다.컴파일할 테스트가 없으면 실행할 테스트가 없습니다.

는 이 의 답을 , 제 답에 대해 과 같이 .pom.xml.

org.junit.jupiter 의존

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.2.0</version>
    </dependency>
</dependencies>

요.maven-surefire-plugin 및 """mvn clean install/test아래 테스트 파일을 검색하기 시작했습니다.src/test/java

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <dependencies>
    <!-- moved here -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.2.0</version>
        </dependency>
    </dependencies>
</plugin>

junitArtifactName 중인 이 아닌 에도 해당될 수 .junit:junit, 예를 ★★★★★★★★★★★★★★★...

<dependency>
    <groupId>org.eclipse.orbit</groupId>
    <artifactId>org.junit</artifactId>
    <version>4.11.0</version>
    <type>bundle</type>
    <scope>test</scope>
</dependency>

언급URL : https://stackoverflow.com/questions/6178583/maven-does-not-find-junit-tests-to-run

반응형