这是我在mvn
中的项目结构:
你可以注意到,我在src/test/java
中有两个类:
CardValidtorIT.java
(这是集成测试)CardValidatorTest.java
(这是单元测试)
当我运行
mvn package
我发现只运行了unit-test (CardValidatorTest.java)
但是当我运行
mvn integration-test
我看到同时运行了unit-test
和Integration tests
。
mvn
如何知道在运行mvn package
时不执行CardValidatorIT.java
?也就是说,为什么它没有运行CardValidatoryIT.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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>chapter14</artifactId>
<groupId>org.agoncal.book.javaee7</groupId>
<version>1.0</version>
</parent>
<groupId>org.agoncal.book.javaee7.chapter14</groupId> <artifactId>chapter14-service</artifactId> <version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.glassfish.main.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.12.4</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
P.S:我知道在mvn中有一个integration-test
目标,但我没有将该目标与应在集成测试期间运行的类绑定。
谢谢
mvn test
只运行了一个测试(cardValidatorTest),mvn package
仅运行了一个测试(CardValidatorTest),但是mvn integration-test
运行了两个测试(CardValidatorTest 和 CardValidatorIT)。但你的答案和链接都帮助了我!谢谢 - brain stormfailsafe
插件的情况下知道哪些测试是集成测试?即使项目的pom文件中没有failsafe
插件,这些测试也会被执行。项目的pom文件只有一个spring-boot-starter-parent
作为其父项目,并且集成测试使用了*IntegrationTest
后缀(这不是默认的后缀)。 - undefined