gpt4 book ai didi

maven - 如何使用 Maven Surefire 插件调用 JUnit5 测试运行器/Junit 标记表达式?

转载 作者:行者123 更新时间:2023-12-04 14:55:26 24 4
gpt4 key购买 nike

我们正在构建一个模块化框架来运行 API 测试。使用 JUnit/JUnit5 @Test 注释对测试本身进行注释。

选项 1:

  1. 为了一起运行测试,我创建了 JUnit5 测试运行器并且在 IntelliJ IDE 中使用本地运行器测试运行良好

选项 2:

  1. 此外,除了上述方法,我们已经开始添加 JUnit5 标签来对测试进行分类

A) 当我尝试使用 Maven surefire 插件调用上述选项 1 中提到的 JUnit5 runner 时,没有测试运行。

B) 此外,当我尝试在 Surefire 插件中使用以下方法运行标签时,预期的测试不会运行:

                 <properties>
<includeTags>SignUpTag,junit5Tag,ListingTag,dummy</includeTags>
</properties>

<!-- OR-->
<groups>signUpTag,junit5Tag,listingTag,dummy,loginTag</groups>

您是否有关于使用 Maven suirefire 插件调用 JUnit5 测试套件的 Git 等示例示例?

非常感谢

enter image description here

enter image description here

POM.XML

<properties>
<java.version>11</java.version>
<maven.compiler.version>3.3</maven.compiler.version>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<rest.assured.version>4.3.1</rest.assured.version>
<testng.version>7.3.0</testng.version>
<mvn.scala.version>2.15.2</mvn.scala.version>
<jackson.databind.version>2.9.0</jackson.databind.version>
<commons-io.version>2.1</commons-io.version>
<wiremock.version>2.24.1</wiremock.version>
<log4j.version>LATEST</log4j.version>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<junit.platform.version>1.5.2</junit.platform.version>
<hamcrest.version>2.2</hamcrest.version>
<tests>ListingTag</tests>
</properties>

<profiles>
<profile>
<id>allTests</id>
<properties>
<tests>SignUpTag,junit5Tag,listingTag,dummy,loginTag</tests>
</properties>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest.assured.version}</version>
</dependency>

<dependency>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>${mvn.scala.version}</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.testng</groupId>-->
<!-- <artifactId>testng</artifactId>-->
<!-- <version>${testng.version}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.databind.version}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.0-alpha1</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!--****************************** OPTION 1: ***************************-->
<!--************************************************************************-->
<includes>
<include>Junit5RunnerIT.java</include>
<include>**/Junit5RunnerIT*.java</include>
<include>**/*Junit5RunnerIT.java</include>
</includes>
<!-- <testFailureIgnore>true</testFailureIgnore>-->
<!--************************************************************************-->
<!--****************************** OPTION 2: ***************************-->
<!--************************************************************************-->
<properties>
<includeTags>signUpTag,junit5Tag,ListingTag,dummy</includeTags>
</properties>
<!-- <groups>junit5</groups>-->
<!-- <groups>${tests}</groups>-->
<groups>signUpTag,junit5Tag,listingTag,dummy,loginTag</groups>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

最佳答案

这就是我所做的,不确定这是否是您要找的东西。

pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<groups>Demo1Test,Demo2Test,Demo3Test,Demo4Test</groups>
</configuration>
</plugin>

样本测试

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

@Tag("Demo1Test")
public class Demo1Test {

@Test
void name1(TestInfo info) {
System.out.println(info.getDisplayName());
}
}

运行mvn clean test。这是结果:

enter image description here

关于maven - 如何使用 Maven Surefire 插件调用 JUnit5 测试运行器/Junit 标记表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68119830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com