# maven4test
**Repository Path**: Protector_hui/maven4test
## Basic Information
- **Project Name**: maven4test
- **Description**: 通过maven配置变量,以达到用不同的命令执行单元测试/集成测试
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-11-13
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
@[toc]
## 前提
项目中一般会包含两种测试:单元测试 + 集成测试。为了方便管理,我个人偏向于将这两种测试放在不同的文件夹下。
## 项目结构

## pom.xml
### 添加源文件
```xml
org.codehaus.mojo
build-helper-maven-plugin
3.0.0
add-integration-test-sources
generate-test-sources
add-test-source
src/int/java
add-integration-test-resources
generate-test-resources
add-test-resource
src/int/resources
```
## 设置参数
```xml
skipTests
true
true
true
unit
true
false
int
false
true
tests
false
false
```
### 单元测试 & 集成测试的区分
以`.Test.java`结尾的文件为单元测试,以`.IntTest.java`结尾的文件为集成测试
```xml
org.apache.maven.plugins
maven-surefire-plugin
${skipUnitTest}
**/*Test.java
**/*IntTest.java
org.apache.maven.plugins
maven-failsafe-plugin
${skipIntTest}
**/*IntTest.java
```
## 运行结果展示
### 不执行任何测试
```shell
mvn clean install -P skipTests
```
**结果**

### 只执行单元测试
```shell
mvn clean install -P unit
```
**结果**

### 只执行集成测试
```shell
mvn clean install -P int
```
**结果**

### 全都执行
```shell
mvn clean install -P tests
```
**结果**

## 项目代码
[Maven For Test](https://gitee.com/Protector_hui/maven4test)