【发布时间】:2021-09-08 04:32:21
【问题描述】:
我们正在构建一个模块化框架来运行 API 测试。 使用 JUnit / JUnit5 @Test 注释对它们自己的测试进行注释。
选项1:
- 为了一起运行测试,我创建了 JUnit5 测试运行器 并且测试在 IntelliJ IDE 中使用本地运行程序运行良好
选项2:
- 此外,作为上述方法的替代方案,我们已经开始添加 JUnit5 标记来对测试进行分类
A) 当我尝试使用 Maven surefire 插件调用上述选项 1 中提到的 JUnit5 运行器时,没有运行测试。
B) 此外,当我尝试在 Surefire 插件中使用以下方法运行标签时,预期的测试不会运行:
<properties>
<includeTags>SignUpTag,junit5Tag,ListingTag,dummy</includeTags>
</properties>
<!-- OR-->
<groups>signUpTag,junit5Tag,listingTag,dummy,loginTag</groups>
你有关于 Git 等关于使用 Maven suirefire 插件调用 JUnit5 测试套件的示例示例吗?
非常感谢
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>
【问题讨论】:
-
注意-我已经尝试过以下问题的答案,但没有奏效:stackoverflow.com/questions/42421688/…
标签: maven junit junit5 rest-assured maven-surefire-plugin