【发布时间】:2018-03-10 15:05:55
【问题描述】:
我正在尝试通过 maven 命令分离单元测试和集成测试。
pom.xml
....
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Fast*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我的集成测试
@RunWith(SpringRunner.class)
@SpringBootTest(classes = StudentApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class StudentControllerIT {
...
这是单元测试
@RunWith(SpringRunner.class)
@WebMvcTest(value = StudentController.class, secure = false)
public class StudentFastControllerTest {
....
现在,当我尝试运行命令 mvn test 时,只执行 StudentFastControllerTest 测试,但是当我运行命令 mvn integration-test 或 mvn verify 时,两个测试类都被执行,而不是仅执行 StudentControllerIT。
【问题讨论】:
标签: maven spring-boot junit4 maven-failsafe-plugin