zoukankan      html  css  js  c++  java
  • maven-surefire-plugin

    本文参考自:https://www.cnblogs.com/qyf404/p/5013694.html

    surefire是maven里执行测试用例(包括testNG,Junit,pojo)的插件,他能产生两种不同形式的测试结果报告

    1、纯文本 2、.xml文件格式

    核心:这个插件的surefire:test命令会默认绑定maven执行的test阶段,当执行mvn test或者执行其他maven命令时跑了测试用例,那么已经用过maven-surefire-plugin了。

    默认情况下,这些文件生成在工程的${basedir}/target/surefire-reports,目录下(basedir指的是pom文件所在的目录)。 

    如何使用?运行测试即可,例如mvn test,mvn surefire:test,它能扫描测试类目录下的测试类,只要类名符合*Test.java,那么这个测试类就会被运行。

    备注:此插件与单元测试插件配合使用,属于辅助插件。

    ---------------------------------------------------------------------------------------

    配置

    (以junit为例)

    配置junit

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>

    配置maven-surefire-plugin(最简单配置)

    <plugin> 
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.19</version>
    </plugin>

    surefire会自动按一定逻辑寻找Junit插件并执行测试样例,当然也能自己指定

    if the JUnit version in the project >= 4.7 and the parallel attribute has ANY value
        use junit47 provider
    if JUnit >= 4.0 is present
        use junit4 provider
    else
        use junit3.8.1

    ---------------------------------------------------------------------------------------

    常见其他配置

    跳过测试样例

    很多指令,例如mvn package,执行时先会执行mvn test,但如果我们在打包的时候是不想执行测试样例呢?

    例如:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit47</artifactId>
                <version>2.19</version>
            </dependency>
        </dependencies>
        <configuration>
            <skipTests>true</skipTests>
        </configuration>
    </plugin>
  • 相关阅读:
    [转]权限管理模型
    如何解决 “invalid resource directory name”, resource “crunch”
    Oracle ERP Interface堵住--Request Running too long time,查找Request执行的Sql
    【转】令人印象深刻的廣告詞
    【异常】SQL Server blocked access to STATEMENT OpenRowset/OpenDatasource
    你是喜欢一个人本身,还是
    关于Oracle 的安装记(不定期更新)
    kafka
    mysql去除换行和空格
    mysql 字段值拼接,同一字段循环拼接
  • 原文地址:https://www.cnblogs.com/yanze/p/10599888.html
Copyright © 2011-2022 走看看