maven surefire的executions配置
以前一直稀里糊涂的配置surefire插件,还出现用例被执行2次的问题。现在刚搞清楚,原来是我多配置了一个execution导致的。
每个execution都可以配置一套不同的参数,execution使用id来区分,比如 exec1,
<plugin> <!--surefire的基本属性--> <executions> <execution> <id>exec1</id> <goals> <goal>test</goal> </goals> <configuration> <reuseForks>true</reuseForks> <forkCount>2</forkCount> </configuration> </execution> </executions> </plugin>
在执行的时候可以使用
mvn surefire:test@exec1
来执行特定的execution(这里一定要用surefire:test ,直接用test不行,不能加@),很方便.可以使用在用例分级(分类)测试上。不同环境使用不同的参数。比如提交时运行单元测试(非常快),特定的时候(比如手动触发)运行功能测试、集成测试。分类测试可以参考官网 中的Using JUnit Categories部分