美文网首页
2020-05-19Api_ Log4j+Allure

2020-05-19Api_ Log4j+Allure

作者: testerPM | 来源:发表于2020-05-19 09:54 被阅读0次

    Log4j

    (1)pom.xml导入Log4j的坐标

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    
    

    (2)配置log4j.properties配置文件,放在resource目录下即可(网上找copy即可)

    
    log4j.rootLogger = INFO,console,file
    
    log4j.appender.console = org.apache.log4j.ConsoleAppender
    log4j.appender.console.Target = System.out
    log4j.appender.console.layout = org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern = [%p] %d{yyyy-MM-dd HH:mm:ss} method: %l----%m%n   //日志输出格式
    
    log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.file.File = log/api_auto.log //日志存放路径
    log4j.appender.file.Append = false//日志不追加,每次清空
    log4j.appender.file.layout = org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} method: %l - [ %p ]----%m%n
    
    

    (3)如何使用
    一般日志用来输出重要的字段或者需要关注的信息会加日志
    一般在哪个类中使用,就要重新写入下面的代码,在哪个类文件中使用,就传入各自的类
    即:哪个类需要打印日志,就在哪个类重新定义一下logger

     private Logger logger = Logger.getLogger(LoginCase.class);
            
    

    如下面:给LoginCase.Java加日志:下图代码中System.out.println()语句便可以注释掉,这两句代码的区别,日志既可以输出到控制台,也可以写入文件,而system.out.println();只能打印到控制台

    
    package com.lemon.cases;
    
    import org.apache.log4j.Logger;
    import org.testng.annotations.AfterSuite;
    import org.testng.annotations.BeforeSuite;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    import com.lemon.constant.Constant;
    import com.lemon.pojo.Api;
    import com.lemon.pojo.Cases;
    import com.lemon.utils.AuthenticationUtils;
    import com.lemon.utils.DataUtils;
    import com.lemon.utils.ExcelUtils;
    
    public class LoginCase extends BaseCase {
    //注意传入的类不能错,在哪个类使用,就传入哪个类
    //这里用的是private,也可以是其他
        private Logger log = Logger.getLogger(LoginCase.class);
    
        @BeforeSuite
        public void init() {
                         //此注释代码不能放在方法里面(会报错??),需要作为类的成员变量
            // private Logger logger = Logger.getLogger(LoginCase.class);
                     //此注释代码放在方法里为何没有报错???
            //Logger log = Logger.getLogger(LoginCase.class);
            log.info("项目启动");
            // 套件执行初始化:配置参数化变量
            AuthenticationUtils.env.put(Constant.REGISTER_MOBILEPHONE_TEXT, Constant.REGISTER_MOBILEPHONE_VALUE);
            AuthenticationUtils.env.put(Constant.REGISTER_PASSWORD_TEXT, Constant.REGISTER_PASSWORD_VALUE);
            AuthenticationUtils.env.put(Constant.LOGIN_MOBILEPHONE_TEXT, Constant.LOGIN_MOBILEPHONE_VALUE);
            AuthenticationUtils.env.put(Constant.LOGIN_PASSWORD_TEXT, Constant.LOGIN_PASSWORD_VALUE);
    
        }
    
        @Test(dataProvider = "datas")
        public void testLogin(Api api, Cases cases) {
            //接口参数变量替换
            String params = paramsReplace(cases.getParams());
            log.info("替换后的params:" + params);
            // System.out.println("替换后的params:" + params);
            //将替换后的params塞到cases对象里
            cases.setParams(params);
            // sql参数替换
            String SQLparams = paramsReplace(cases.getSql());
            log.info("替换后的SQLparams :" + SQLparams);
            // System.out.println("替换后的SQLparams :" + SQLparams);
            //替换的后的sql塞到cases对像里面
            cases.setSql(SQLparams);
            
            // 获取响应
            String actualResponseBody = ActualResponseBody(api, cases);// 子类调用父类方法
            // 添加回写---原生poi+list
            addWriteBackData(cases, actualResponseBody);
            boolean assertResponseData = AssertResponseData(cases, actualResponseBody);
            log.info("断言结果:" + assertResponseData);
            // System.out.println("断言结果:" + assertResponseData);
    
        }
    
        @AfterSuite
        public void finish() {
            // 套件执行完毕之后,执行批量回写
            ExcelUtils.WriteBackResponseBody(Constant.EXCEL_PATH, 1);
        }
    
        // 数据支持,与test()方法发生关联,提供url和params
        @DataProvider(name = "datas")
        public Object[][] datas() {
            Object[][] datas = DataUtils.getApiandCasesByApiId("2");
            return datas;
        }
    }
    
    
    

    执行LoginCase.java(在项目根目录下会自动生成log/api_auto.log),日志结果如下:

    2020-05-19 11:00:02 method: com.lemon.cases.LoginCase.init(LoginCase.java:24) - [ INFO ]----项目启动
    2020-05-19 11:00:04 method: org.hibernate.validator.internal.util.Version.<clinit>(Version.java:30) - [ INFO ]----HV000001: Hibernate Validator 5.2.4.Final
    2020-05-19 11:00:04 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:37) - [ INFO ]----替换后的params:{"mobile_phone":"15505182352","pwd":"123456789"}
    2020-05-19 11:00:04 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:43) - [ INFO ]----替换后的SQLparams :
    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53) - [ INFO ]----断言结果:false
    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:37) - [ INFO ]----替换后的params:{"mobile_phone":"15505182352","pwd":"123456789"}
    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:43) - [ INFO ]----替换后的SQLparams :
    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53) - [ INFO ]----断言结果:true
    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:37) - [ INFO ]----替换后的params:{"mobile_phone":"15505182352","pwd":""}
    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:43) - [ INFO ]----替换后的SQLparams :
    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53) - [ INFO ]----断言结果:true
    
    

    日志分析:下图日志中method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53)表示执行的是LoginCase类中的第53行代码

    2020-05-19 11:00:05 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53) - [ INFO ]----断言结果:true
    
    

    Allure

    (1)pom.xml导入坐标allure-testng

    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.6.0</version>
    </dependency>
    
    
    

    (2) pom.xml导入插件(下面代码allure官网提供)

    下面代码在pom中与<dependencies></dependencies>标签同级别

    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <!-- maven-surefire-plugin 配合testng/junit执行测试用例的maven插件 -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                    <configuration>
                        <!-- 测试失败后,是否忽略并继续测试,true代表失败继续执行 -->
                        <testFailureIgnore>true</testFailureIgnore>
                        <suiteXmlFiles>
                            <!-- testng配置文件名称,testng.xml必须是在项目的根目录下此处才能这样写 -->
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                        <!--设置参数命令行 -->
                        <argLine>
                            <!-- UTF-8编码 -->
                            -Dfile.encoding=UTF-8
                            <!-- 配置拦截器 -->
                            -
                            javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjw
                            eaver-${aspectj.version}.jar"
                        </argLine>
                        <systemProperties>
                            <property>
                                <!-- 配置 allure 结果存储路径,如果不配置默认生成在项目的根路径下 -->
                                <name>allure.results.directory</name>
                                <value>${project.build.directory}/allure-results</value>
                            </property>
                        </systemProperties>
                    </configuration>
                    <dependencies>
                        <!-- aspectjweaver maven坐标 -->
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    
    
    
    

    (3)properties里面加上<aspectj.version>1.8.10</aspectj.version>,否则运行报表会报错:报${aspectj.version}版本无效

    
    <properties>
            <aspectj.version>1.8.10</aspectj.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
        </properties>
    
    

    报表执行流程:

    第一步:先执行maven命令即maven test
    执行src/test文件夹下面所有的类不过需要结合testng.xml,testng.xml里面配好的类才会跑
    第二步:io.qameta.allure:allure-maven:serve 启动报表服务器

    maven常用命令:

    1.maven test: 执行test文件夹中所有代码
    2.maven package: 把当前项目打包(打包前会先执行test,如果test失败,打包会失败)
    3.maven clean: 清空当前项目下的maven生成的文件(即清空package)
    4.maven install: 把jar包安装到本地仓库(即:也是打jar包(也会先执行test,然后再打包package),然后放在你本地配置好的maven路径下)
    注意:打包是打src/main下面的代码,而我们的代码是放在src/test下面,所以打出来的包是空的

    5.maven build...: 用来写maven命令(命令允许组合使用)
    如 Goals: clean test
    即先执行clean 再执行test

    运行报表:

    参考http://www.lemfix.com/topics/349

    1. maven build... : 配置命令 clean test-》点击 run
      第一次启动,会先去下载插件
      控制台打印下面信息,说明clean test执行成功
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] -----------------------< com.lemon:auto_api_v9 >------------------------
    [INFO] Building auto_api_v9 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-surefire-plugin/2.22.2/maven-surefire-plugin-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-surefire-plugin/2.22.2/maven-surefire-plugin-2.22.2.pom (5.0 kB at 1.6 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire/2.22.2/surefire-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire/2.22.2/surefire-2.22.2.pom (26 kB at 19 kB/s)
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ auto_api_v9 ---
    [INFO] Deleting D:\workspace2018\java_day09_api_autoV6_01\target
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ auto_api_v9 ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory D:\workspace2018\java_day09_api_autoV6_01\src\main\resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ auto_api_v9 ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ auto_api_v9 ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 2 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ auto_api_v9 ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 15 source files to D:\workspace2018\java_day09_api_autoV6_01\target\test-classes
    [WARNING] /D:/workspace2018/java_day09_api_autoV6_01/src/test/java/com/lemon/utils/SQLUtils.java: 某些输入文件使用了未经检查或不安全的操作。
    [WARNING] /D:/workspace2018/java_day09_api_autoV6_01/src/test/java/com/lemon/utils/SQLUtils.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ auto_api_v9 ---
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/aspectj/aspectjweaver/1.9.2/aspectjweaver-1.9.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/aspectj/aspectjweaver/1.9.2/aspectjweaver-1.9.2.pom (1.0 kB at 3.2 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/maven-surefire-common/2.22.2/maven-surefire-common-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/maven-surefire-common/2.22.2/maven-surefire-common-2.22.2.pom (11 kB at 25 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-api/2.22.2/surefire-api-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-api/2.22.2/surefire-api-2.22.2.pom (3.5 kB at 4.1 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-logger-api/2.22.2/surefire-logger-api-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-logger-api/2.22.2/surefire-logger-api-2.22.2.pom (2.0 kB at 4.7 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-booter/2.22.2/surefire-booter-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-booter/2.22.2/surefire-booter-2.22.2.pom (7.5 kB at 20 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/aspectj/aspectjweaver/1.9.2/aspectjweaver-1.9.2.jar
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-api/2.22.2/surefire-api-2.22.2.jar
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/maven-surefire-common/2.22.2/maven-surefire-common-2.22.2.jar
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-logger-api/2.22.2/surefire-logger-api-2.22.2.jar
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-booter/2.22.2/surefire-booter-2.22.2.jar
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-logger-api/2.22.2/surefire-logger-api-2.22.2.jar (13 kB at 18 kB/s)
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-booter/2.22.2/surefire-booter-2.22.2.jar (274 kB at 323 kB/s)
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-api/2.22.2/surefire-api-2.22.2.jar (186 kB at 84 kB/s)
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/maven-surefire-common/2.22.2/maven-surefire-common-2.22.2.jar (528 kB at 95 kB/s)
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/aspectj/aspectjweaver/1.9.2/aspectjweaver-1.9.2.jar (2.1 MB at 212 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng/2.22.2/surefire-testng-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng/2.22.2/surefire-testng-2.22.2.pom (2.8 kB at 6.5 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-providers/2.22.2/surefire-providers-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-providers/2.22.2/surefire-providers-2.22.2.pom (2.5 kB at 5.9 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/common-java5/2.22.2/common-java5-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/common-java5/2.22.2/common-java5-2.22.2.pom (2.7 kB at 9.5 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng-utils/2.22.2/surefire-testng-utils-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng-utils/2.22.2/surefire-testng-utils-2.22.2.pom (3.4 kB at 11 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-grouper/2.22.2/surefire-grouper-2.22.2.pom
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-grouper/2.22.2/surefire-grouper-2.22.2.pom (2.6 kB at 4.7 kB/s)
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng-utils/2.22.2/surefire-testng-utils-2.22.2.jar
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-grouper/2.22.2/surefire-grouper-2.22.2.jar
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng/2.22.2/surefire-testng-2.22.2.jar
    [INFO] Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/common-java5/2.22.2/common-java5-2.22.2.jar
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng-utils/2.22.2/surefire-testng-utils-2.22.2.jar (27 kB at 52 kB/s)
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-grouper/2.22.2/surefire-grouper-2.22.2.jar (40 kB at 74 kB/s)
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-testng/2.22.2/surefire-testng-2.22.2.jar (44 kB at 73 kB/s)
    [INFO] Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/common-java5/2.22.2/common-java5-2.22.2.jar (51 kB at 2.3 kB/s)
    [INFO] 
    [INFO] -------------------------------------------------------
    [INFO]  T E S T S
    [INFO] -------------------------------------------------------
    [INFO] Running TestSuite
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    [INFO] 2020-05-26 14:36:41 method: com.lemon.cases.LoginCase.init(LoginCase.java:24)----项目启动
       [INFO] 2020-05-26 14:36:51 method: org.hibernate.validator.internal.util.Version.<clinit>(Version.java:30)----HV000001: Hibernate Validator 5.2.4.Final
       [Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Api [id=2, name=login, type=post, url=http://api.lemonban.com/futureloan/member/login, contentType=json], Api [id=3, name=recharge, type=post, url=http://api.lemonban.com/futureloan/member/recharge, contentType=json], Api [id=4, name=withdraw, type=post, url=http://api.lemonban.com/futureloan/member/withdraw, contentType=json], Api [id=5, name=update, type=PATCH, url=http://api.lemonban.com/futureloan/member/update, contentType=json], Api [id=6, name=invest, type=post, url=http://api.lemonban.com/futureloan/member/invest, contentType=json], Api [id=7, name=info, type=get, url=http://api.lemonban.com/futureloan/member/{member_id}/info, contentType=json], Api [id=8, name=add, type=post, url=http://api.lemonban.com/futureloan/loan/add, contentType=json], Api [id=9, name=audit, type=PATCH, url=http://api.lemonban.com/futureloan/loan/audit, contentType=json], Api [id=10, name=generateRepayments, type=get, url=http://api.lemonban.com/futureloan/loans, contentType=json]]
    [Cases [caseId=1, desc=传手机号,不传密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":""}, apiId=1, expectData={"code":1,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=2, desc=不传手机号,传密码, params={"mobile_phone":"","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":1,"msg":"手机号为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=3, desc=不合格的手机号, params={"mobile_phone":"187","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"无效的手机格式","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=4, desc=合格的手机号,不合格密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"&&&&"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=5, desc=合格的手机号,合格密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData=[{"value":0,"expression":"$.code"}], sql=select count(*) from  member  where mobile_phone=13345454557], Cases [caseId=6, desc=重复以上的手机号-密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=7, desc=重复以上的手机号-密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=8, desc=重复以上的手机号-密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=9, desc=已注册的账号, params={"mobile_phone":"${toBeLoginMobilephone}","pwd":"${toBeLoginPassword}"}, apiId=2, expectData={"code":0,"msg":"OK","data":{"id":84367,"leave_amount":200.0,"mobile_phone":"18715629500","reg_name":"小柠檬","reg_time":"2019-12-17 15:44:19.0","type":1,"token_info":{"token_type":"Bearer","expires_in":"2019-12-18 10:02:04","token":"eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjg0MzY3LCJleHAiOjE1NzY2MzQ1MjR9.wUTNWi-9f7dqjmRD89oZsTWU1GueggQN6WKpQ0-8XUdVElXarWAKbsZP5yUeQ2sZphSSpOSSiUwIRLA-SiGhkw"}},"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=10, desc=未注册的账号, params={"mobile_phone":"${toBeLoginMobilephone}","pwd":"${toBeLoginPassword}"}, apiId=2, expectData={"code":1001,"msg":"账号信息错误","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=11, desc=未注册的账号,无密码, params={"mobile_phone":"${toBeLoginMobilephone}","pwd":""}, apiId=2, expectData={"code":2,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=12, desc=用户未登陆, params={"member_id":"-1","amount":"300"}, apiId=3, expectData=[{"value":1008,"expression":"$.code"}], sql=null], Cases [caseId=13, desc=负金额, params={"member_id":"${member_id}","amount":"-100"}, apiId=3, expectData=[{"value":2,"expression":"$.code"}], sql=null], Cases [caseId=14, desc=正确的用例, params={"member_id":"${member_id}","amount":"100"}, apiId=3, expectData=[{"value":0,"expression":"$.code"},{"value":"ok","expression":"$.code"}], sql=select  leave_amount from member where id=${member_id}], Cases [caseId=15, desc=非数字, params={"member_id":"${member_id}","amount":"dddd"}, apiId=3, expectData=[{"value":2,"expression":"$.code"}], sql=null]]
    替换后的params:{"mobile_phone":"15903916448","pwd":""}
    替换后的SQLparams :
    输出响应体:{"code":1,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    替换后的params:{"mobile_phone":"","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":1,"msg":"手机号为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    替换后的params:{"mobile_phone":"187","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"无效的手机格式","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    替换后的params:{"mobile_phone":"15903916448","pwd":"&&&&"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"密码格式为8到16位","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    替换后的params:{"mobile_phone":"15903916448","pwd":"123456789"}
    替换后的SQLparams :select count(*) from  member  where mobile_phone=13345454557
    输出响应体:{"code":0,"msg":"OK","data":{"id":100051358,"reg_name":"小柠檬","mobile_phone":"15903916448"},"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    期望值:0,实际值:0,断言结果:true
    数据响应断言结果:true
    数据库断言结果:false
    替换后的params:{"mobile_phone":"15903916448","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    替换后的params:{"mobile_phone":"15903916448","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    替换后的params:{"mobile_phone":"15903916448","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:37)----替换后的params:{"mobile_phone":"15903916448","pwd":"123456789"}
       [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:43)----替换后的SQLparams :
       输出响应体:{"code":0,"msg":"OK","data":{"id":100051358,"leave_amount":0.0,"mobile_phone":"15903916448","reg_name":"小柠檬","reg_time":"2020-05-26 14:36:59.0","type":1,"token_info":{"token_type":"Bearer","expires_in":"2020-05-26 14:42:00","token":"eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjEwMDA1MTM1OCwiZXhwIjoxNTkwNDc1MzIwfQ.8QGD78O2Lrz-LfgkYuxYak6vMM4uyWjRK75_xcmY7PUw6dQKwz9Y3vQlW6KJ2I6u2qOqE79lBlZZEYKejTWlHw"}},"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53)----断言结果:false
       [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:37)----替换后的params:{"mobile_phone":"15903916448","pwd":"123456789"}
       [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:43)----替换后的SQLparams :
       输出响应体:{"code":0,"msg":"OK","data":{"id":100051358,"leave_amount":0.0,"mobile_phone":"15903916448","reg_name":"小柠檬","reg_time":"2020-05-26 14:36:59.0","type":1,"token_info":{"token_type":"Bearer","expires_in":"2020-05-26 14:42:00","token":"eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjEwMDA1MTM1OCwiZXhwIjoxNTkwNDc1MzIwfQ.8QGD78O2Lrz-LfgkYuxYak6vMM4uyWjRK75_xcmY7PUw6dQKwz9Y3vQlW6KJ2I6u2qOqE79lBlZZEYKejTWlHw"}},"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53)----断言结果:false
       [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:37)----替换后的params:{"mobile_phone":"15903916448","pwd":""}
       [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:43)----替换后的SQLparams :
       输出响应体:{"code":1,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    [INFO] 2020-05-26 14:37:00 method: com.lemon.cases.LoginCase.testLogin(LoginCase.java:53)----断言结果:false
       替换后的params:{"member_id":"-1","amount":"300"}
    替换后的SQLparams :
    输出响应体:{"code":1007,"msg":"无权限访问,请检查参数","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    期望值:1008,实际值:1007,断言结果:false
    断言结果:false
    替换后的params:{"member_id":"100051358","amount":"-100"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"余额必须大于0并且小于或者等于500000","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    期望值:2,实际值:2,断言结果:true
    断言结果:true
    替换后的params:{"member_id":"100051358","amount":"100"}
    替换后的SQLparams :select  leave_amount from member where id=100051358
    输出响应体:{"code":0,"msg":"OK","data":{"id":100051358,"leave_amount":100.0,"mobile_phone":"15903916448","reg_name":"小柠檬","reg_time":"2020-05-26 14:36:59.0","type":1},"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    期望值:0,实际值:0,断言结果:true
    期望值:ok,实际值:0,断言结果:false
    断言结果:false
    替换后的params:{"member_id":"100051358","amount":"dddd"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"余额必须为数值型","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    期望值:2,实际值:2,断言结果:true
    断言结果:true
    [INFO] Tests run: 15, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 35.488 s - in TestSuite
    [INFO] 
    [INFO] Results:
    [INFO] 
    [INFO] Tests run: 15, Failures: 0, Errors: 0, Skipped: 0
    [INFO] 
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  01:27 min
    [INFO] Finished at: 2020-05-26T14:37:03+08:00
    [INFO] ------------------------------------------------------------------------
    
    
    
    1. 项目根目录下-> maven build...: 配置命令 io.qameta.allure:allure-maven:serve 启动报表服务器
      目前卡在报表服务启动:
    ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_65;
    
    Please set the JAVA_HOME variable in your environment to match the
    location of your Java installation.
    [ERROR] Can't generate allure report data
    
    

    从报错信息看说是jdk配置无效,目前也不晓得哪里不对:只能 重新配置jdk
    参考文档:http://www.lemfix.com/topics/43433
    JAVA_HOME=D:\jdk (不要加分号,原来c盘的jdk就不用了)
    path= %JAVA_HOME%\bin; (注意有分号),放在最前面
    只需要配置这两个变量即可
    jdk安装过程中不要安装jre,如果看到 提示安装jre弹窗,x掉即可
    jdk配置成功,eclispe->window->preferences->java->install jre->add: 将D:\jdk添加进来,原来c盘下面的jdk remove掉即可,为了防止jdk不生效 重启eclipse->项目根目录下重新 执行 maven build...-> io.qameta.allure:allure-maven:serve 启动报表服务器,如果console出现下面日志(最后一行url),说明启动成功(浏览器会自动打开allure,如果没有自动打开,可以自己手动输入url)

    [INFO] Scanning for projects...
    [INFO] 
    [INFO] -----------------< com.lemon:java_day09_api_autoV6_01 >-----------------
    [INFO] Building java_day09_api_autoV6_01 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- allure-maven:2.10.0:serve (default-cli) @ java_day09_api_autoV6_01 ---
    [INFO] Allure installation directory D:\workspace2018\java_day09_api_autoV6_01/.allure
    [INFO] Try to finding out allure 2.8.1
    [INFO] Generate Allure report (serve) with version 2.8.1
    [INFO] Generate Allure report to D:\workspace2018\java_day09_api_autoV6_01\target\site/allure-maven-plugin
    [INFO] Found results directory D:\workspace2018\java_day09_api_autoV6_01\target\allure-results
    [INFO] Can't find information about categories.
    [INFO] Generate report to D:\workspace2018\java_day09_api_autoV6_01\target\site\allure-maven-plugin
    Generating report to temp directory...
    Report successfully generated to C:\Users\USER\AppData\Local\Temp\7444666075419720523\allure-report
    Starting web server...
    2020-05-26 16:38:52.232:INFO::main: Logging initialized @9789ms to org.eclipse.jetty.util.log.StdErrLog
    Server started at <http://192.168.4.196:64117/>. Press <Ctrl+C> to exit
    
    

    虽然maven test编译通过,但是用我自己的pom文件执行test,总是报下面的错误

    Please refer to D:\workspace2018\java_day09_api_autoV6_01\target\surefire-reports for the individual test results.
    Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
    The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
    Command was cmd.exe /X /C "D:\jdk\jre\bin\java -Dfile.encoding=UTF-8                                                - "                     javaagent:D:\apache-maven-3.6.2\repository/org/aspectj/aspectjweaver/1.8.10/aspectjw                        eaver-1.8.10.jar" -jar C:\Users\USER\AppData\Local\Temp\surefire6860202223865796549\surefirebooter1210306921226339789.jar C:\Users\USER\AppData\Local\Temp\surefire6860202223865796549 2020-05-27T09-28-00_675-jvmRun1 surefire5816670081112573086tmp surefire_0317655726421201601tmp"
    Error occurred in starting fork, check output in log
    Process Exit Code: 1
    org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
    Command was cmd.exe /X /C "D:\jdk\jre\bin\java -Dfile.encoding=UTF-8                                                - "                     javaagent:D:\apache-maven-3.6.2\repository/org/aspectj/aspectjweaver/1.8.10/aspectjw                        eaver-1.8.10.jar" -jar C:\Users\USER\AppData\Local\Temp\surefire6860202223865796549\surefirebooter1210306921226339789.jar C:\Users\USER\AppData\Local\Temp\surefire6860202223865796549 2020-05-27T09-28-00_675-jvmRun1 surefire5816670081112573086tmp surefire_0317655726421201601tmp"
    Error occurred in starting fork, check output in log
    
    

    maven test编译通过的pom文件如下:

    
    <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>
        <groupId>com.lemon</groupId>  
        <artifactId>auto_api_v9</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <properties>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.source>1.8</maven.compiler.source>
            <!-- 文件拷贝时的编码 -->
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <!-- 编译时的编码 -->
            <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.8.8</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.6</version>
            </dependency>
    
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.47</version>
            </dependency>
    
            <dependency>
                <groupId>cn.afterturn</groupId>
                <artifactId>easypoi-annotation</artifactId>
                <version>4.0.0</version>
            </dependency>
    
            <dependency>
                <groupId>cn.afterturn</groupId>
                <artifactId>easypoi-base</artifactId>
                <version>4.0.0</version>
            </dependency>
            
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>5.2.4.Final</version>
            </dependency>
            <dependency>
                <groupId>javax.el</groupId>
                <artifactId>javax.el-api</artifactId>
                <version>2.2.4</version>
            </dependency>
            <!-- mysql数据库驱动 -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.38</version>
            </dependency>
            
            <!-- 数据库连接工具包 -->
            <dependency>
                <groupId>commons-dbutils</groupId>
                <artifactId>commons-dbutils</artifactId>
                <version>1.6</version>
            </dependency>
            
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            
            <dependency>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-testng</artifactId>
                <version>2.6.0</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        
        
        
        <build>
            <plugins>
                <plugin>
                    <!-- maven-surefire-plugin 配合testng/junit执行测试用例的maven插件 -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.2</version>
                    <configuration>
                        <!-- 测试失败后,是否忽略并继续测试 -->
                        <testFailureIgnore>true</testFailureIgnore>
                        <suiteXmlFiles>
                            <!-- testng配置文件名称 -->
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                        <!--设置参数命令行 -->
                        <forkCount>3</forkCount>
                        <reuseForks>true</reuseForks>
                        <argLine>
                            -Xmx1024m -XX:MaxPermSize=256m
                            <!-- UTF-8编码 -->
                            -Dfile.encoding=UTF-8 
                            <!-- 配置拦截器 -->
                            -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.2/aspectjweaver-1.9.2.jar"
                        </argLine>
                        <systemProperties>
                            <property>
                                <!-- 配置 allure 结果存储路径 -->
                                <name>allure.results.directory</name>
                                <value>${project.build.directory}/allure-results</value>
                            </property>
                        </systemProperties>
                    </configuration>
                    <dependencies>
                        <!-- aspectjweaver maven坐标 -->
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>1.9.2</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    </project>
    
    
    

    maven test 编译不通过的pom文件如下:

    <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>
        <groupId>com.lemon</groupId>
        <artifactId>java_day09_api_autoV6_01</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <properties>
            <!-- jdk版本,如果不配置,默认是1.5 -->
            <maven.compiler.target>1.8</maven.compiler.target>
    
            <maven.compiler.source>1.8</maven.compiler.source>
    
            <!-- 文件拷贝的编码 -->
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    
            <!-- 编译时编码 -->
            <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    
            <aspectj.version>1.8.10</aspectj.version>
    
    
        </properties>
        <dependencies>
    
            <!-- https://mvnrepository.com/artifact/org.testng/testng -->
            <dependency>
    
                <groupId>org.testng</groupId>
    
                <artifactId>testng</artifactId>
    
                <version>6.9.9</version>
    
                <scope>test</scope>
    
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    
            <dependency>
    
                <groupId>org.apache.httpcomponents</groupId>
    
                <artifactId>httpclient</artifactId>
    
                <version>4.5.6</version>
    
            </dependency>
            <!-- <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> 
                <version>3.17</version> </dependency> -->
            <dependency>
                <groupId>cn.afterturn</groupId>
                <artifactId>easypoi-base</artifactId>
                <version>4.0.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>cn.afterturn</groupId>
                <artifactId>easypoi-annotation</artifactId>
                <version>4.0.0</version>
            </dependency>
    
            <dependency>
    
                <groupId>dom4j</groupId>
    
                <artifactId>dom4j</artifactId>
    
                <version>1.6.1</version>
    
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.47</version>
            </dependency>
            <dependency>
                <groupId>javax.el</groupId>
                <artifactId>javax.el-api</artifactId>
                <version>2.2.4</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>5.2.4.Final</version>
            </dependency>
    
    
            <!--mysql数据库驱动 -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.38</version>
            </dependency>
            <!-- 数据库连接工具包DButils -->
            <dependency>
                <groupId>commons-dbutils</groupId>
                <artifactId>commons-dbutils</artifactId>
                <version>1.6</version>
            </dependency>
    
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
    
        </dependencies>
    
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <!-- maven-surefire-plugin 配合testng/junit执行测试用例的maven插件 -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                    <configuration>
                        <!-- 测试失败后,是否忽略并继续测试 -->
                        <testFailureIgnore>true</testFailureIgnore>
                        <suiteXmlFiles>
                            <!-- testng配置文件名称 -->
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                        <!--设置参数命令行 -->
                        <argLine>
                            <!-- UTF-8编码 -->
                            -Dfile.encoding=UTF-8
                            <!-- 配置拦截器 -->
                            -
                            javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjw
                            eaver-${aspectj.version}.jar"
                        </argLine>
                        <systemProperties>
                            <property>
                                <!-- 配置 allure 结果存储路径 -->
                                <name>allure.results.directory</name>
                                <value>${project.build.directory}/allure-results</value>
                            </property>
                        </systemProperties>
                    </configuration>
                    <dependencies>
                        <!-- aspectjweaver maven坐标 -->
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    </project>
    
    
    

    猜测是不是与下面的参数有关系?但是加上了还是报错,目前未找到原因

            <!--设置参数命令行 -->
                        <forkCount>3</forkCount>
                        <reuseForks>true</reuseForks>
                        <argLine>
                            -Xmx1024m -XX:MaxPermSize=256m
                            <!-- UTF-8编码 -->
                            -Dfile.encoding=UTF-8 
    
                        </argLine>
    

    总结:

    1. allure报表执行就2步:
      (1)maven build...运行 clean test(清空target 重新生成报表数据(即一堆json文件)
      (2)maven build...运行io.qameta.allure:allure-maven:server 启动报表服务器
      2.每次重启报表服务,最好先把之前的关掉再重启(否则后台会运行多个,消耗内存)
      3.allure报表是在线服务,如果停掉服务,就看不了了

    Allure加注解可以展示(注解只能加在方法上)

    如果需要加上一些文字说明:
    1. @test(dataProvider="data", description="测试登录接口")

    1. @Step("回写excel")详细描写自动化程序的每个执行步骤
      如果需要在注解上打印参数,可以这么写:
        /**
         * 传入用例信息调用HTTP接口,返回响应数据
         * 如果你想在allure报表上看到输出的参数,如url,以及请求体参数,可以像下面这么写 @Step("第三步:获取响应体{api.url}/{cases.params}")
         * 步骤注解@Step()括号里可以直接传字符串,也可以加你要打印的参数,不过需要用花括号 @Step("第三步:获取响应体")
         * 
         * @param api
         * @param cases
         * @return
         */
        @Step("第三步:获取响应体,打印参数url和params,{api.url}/{cases.params}")
        public String ActualResponseBody(Api api, Cases cases) {
            String url = api.getUrl();
            String params = cases.getParams();
            String type = api.getType();
            String contentType = api.getContentType();
            return HttpUtils.call(url, params, type, contentType);
    
        }
    
    
        @Step("第一步:参数变量替换,打印{params}")
        public String paramsReplace(String params) {
            // 判断params为空的处理
            if (StringUtils.isBlank(params)) {
                return "";
            }
    }
    
    
    

    加了注解之后,需要重新生成allure报表文件:可以不用再通过maven build...,此时我们可以点击 maven build 不带三个点的,因为这里记录了之前操作过的命令,从这里执行也是可以的

    image.png

    上图报告中为什么有三个init(),因为登录,充值,注册三个测试类,都加了参数化替换初始配置(下面代码),所以会初始化三次,而回写只在登录测试类写了,所以Tear Down里面只有一个finish()

        @BeforeSuite
        public void init() {
            // 套件执行初始化:配置参数化变量
            AuthenticationUtils.env.put(Constant.REGISTER_MOBILEPHONE_TEXT, Constant.REGISTER_MOBILEPHONE_VALUE);
            AuthenticationUtils.env.put(Constant.REGISTER_PASSWORD_TEXT, Constant.REGISTER_PASSWORD_VALUE);
            AuthenticationUtils.env.put(Constant.LOGIN_MOBILEPHONE_TEXT, Constant.LOGIN_MOBILEPHONE_VALUE);
            AuthenticationUtils.env.put(Constant.LOGIN_PASSWORD_TEXT, Constant.LOGIN_PASSWORD_VALUE);
    
        }
    
    

    上图报告中共跑了15个case,显示都是pass,这个pass不能直观的说明我们的测试用例测试结果pass多少个,fail多少个,allure报表pass代表的是我们的代码没有没错,每个case都跑成功了,并不是测试结果的统计,那么如何统计呢?

    Allure报表统计测试结果

    以注册接口为例,代码如下(登录,充值另外补充)

        @Test(dataProvider = "datas", description = "测试注册接口")
    
        public void testRegister(Api api, Cases cases) {
            // 接口参数变量替换
            String params = paramsReplace(cases.getParams());
            System.out.println("替换后的params:" + params);
            // 将替换后的params塞到cases对象里
            cases.setParams(params);
            // sql参数替换
            String SQLparams = paramsReplace(cases.getSql());
            System.out.println("替换后的SQLparams :" + SQLparams);
            // 替换的后的sql塞到cases对像里面
            cases.setSql(SQLparams);
    
            // 数据库前置查询结果
            String sql = cases.getSql();
            Object beforeSqlResult = SQLUtils.Query(sql);// 这里不使用强转(将Object类型转成long类型)因为sql为空不能转成long
            // System.out.println(beforeSqlResult.getClass());//查看beforeSqlResult 数据类型
    
            // 获取响应
            String actualResponseBody = ActualResponseBody(api, cases);// 子类调用父类方法
            // 添加回写
            addWriteBackData(cases, actualResponseBody);
            // 响应结果断言
            boolean assertResponseData = AssertResponseData(cases, actualResponseBody);
            System.out.println("数据响应断言结果:" + assertResponseData);
            // 数据库后置查询结果
            Object afterSqlResult = SQLUtils.Query(sql);
            // 数据库断言,没有sql,默认sql断言就是true
            boolean assertSqlResult = true;
            if (StringUtils.isNoneBlank(sql)) {
                assertSqlResult = assertSql(beforeSqlResult, afterSqlResult);
                System.out.println("数据库断言结果:" + assertSqlResult);
            }
            // 测试结果断言: 响应断言和sql断言都通过,测试结果则为通过,passContent目前加回写代码(后面优化)
            String passContent = (assertResponseData && assertSqlResult) ? "pass" : "fail";
            System.out.println("sql断言结果:" + assertSqlResult);
            // 报表统计 测试结果断言的结果:即有多少case是pass,多少是fail
            Assert.assertEquals(passContent, "pass");
        }
    
    

    上述代码中使用testng自带的断言方法(如下),如果断言失败,此句代码就会抛异常
    (登录,充值另外补充,只需要加上下面一句代码即可)

    //testng自带的断言方法
    Assert.assertEquals(passContent, "pass");
    

    执行 Run as->testNG test,控制台打印结果如下:

    [RemoteTestNG] detected TestNG version 6.8.9
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    [TestNG] Running:
      C:\Users\USER\AppData\Local\Temp\testng-eclipse--1103653266\testng-customsuite.xml
    
    [AppClassLoader@18b4aac2] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
    [INFO] 2020-05-27 12:24:47 method: org.hibernate.validator.internal.util.Version.<clinit>(Version.java:30)----HV000001: Hibernate Validator 5.2.4.Final
       [Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Api [id=2, name=login, type=post, url=http://api.lemonban.com/futureloan/member/login, contentType=json], Api [id=3, name=recharge, type=post, url=http://api.lemonban.com/futureloan/member/recharge, contentType=json], Api [id=4, name=withdraw, type=post, url=http://api.lemonban.com/futureloan/member/withdraw, contentType=json], Api [id=5, name=update, type=PATCH, url=http://api.lemonban.com/futureloan/member/update, contentType=json], Api [id=6, name=invest, type=post, url=http://api.lemonban.com/futureloan/member/invest, contentType=json], Api [id=7, name=info, type=get, url=http://api.lemonban.com/futureloan/member/{member_id}/info, contentType=json], Api [id=8, name=add, type=post, url=http://api.lemonban.com/futureloan/loan/add, contentType=json], Api [id=9, name=audit, type=PATCH, url=http://api.lemonban.com/futureloan/loan/audit, contentType=json], Api [id=10, name=generateRepayments, type=get, url=http://api.lemonban.com/futureloan/loans, contentType=json]]
    [Cases [caseId=1, desc=传手机号,不传密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":""}, apiId=1, expectData={"code":1,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=2, desc=不传手机号,传密码, params={"mobile_phone":"","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":1,"msg":"手机号为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=3, desc=不合格的手机号, params={"mobile_phone":"187","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"无效的手机格式","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=4, desc=合格的手机号,不合格密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"&&&&"}, apiId=1, expectData={"code":2,"msg":"密码格式为8到16位","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=5, desc=合格的手机号,合格密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData=[{"value":0,"expression":"$.code"}], sql=select count(*) from  member  where mobile_phone=${toBeRegisterMobilephone}], Cases [caseId=6, desc=重复以上的手机号-密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=7, desc=重复以上的手机号-密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=8, desc=重复以上的手机号-密码, params={"mobile_phone":"${toBeRegisterMobilephone}","pwd":"${toBeRegisterPassword}"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=9, desc=已注册的账号, params={"mobile_phone":"${toBeLoginMobilephone}","pwd":"${toBeLoginPassword}"}, apiId=2, expectData={"code":0,"msg":"OK","data":{"id":84367,"leave_amount":200.0,"mobile_phone":"18715629500","reg_name":"小柠檬","reg_time":"2019-12-17 15:44:19.0","type":1,"token_info":{"token_type":"Bearer","expires_in":"2019-12-18 10:02:04","token":"eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjg0MzY3LCJleHAiOjE1NzY2MzQ1MjR9.wUTNWi-9f7dqjmRD89oZsTWU1GueggQN6WKpQ0-8XUdVElXarWAKbsZP5yUeQ2sZphSSpOSSiUwIRLA-SiGhkw"}},"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=10, desc=未注册的账号, params={"mobile_phone":"${toBeLoginMobilephone}","pwd":"${toBeLoginPassword}"}, apiId=2, expectData={"code":1001,"msg":"账号信息错误","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=11, desc=未注册的账号,无密码, params={"mobile_phone":"${toBeLoginMobilephone}","pwd":""}, apiId=2, expectData={"code":2,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=null], Cases [caseId=12, desc=用户未登陆, params={"member_id":"-1","amount":"300"}, apiId=3, expectData=[{"value":1008,"expression":"$.code"}], sql=null], Cases [caseId=13, desc=负金额, params={"member_id":"${member_id}","amount":"-100"}, apiId=3, expectData=[{"value":2,"expression":"$.code"}], sql=null], Cases [caseId=14, desc=正确的用例, params={"member_id":"${member_id}","amount":"100"}, apiId=3, expectData=[{"value":0,"expression":"$.code"},{"value":"ok","expression":"$.code"}], sql=select  leave_amount from member where id=${member_id}], Cases [caseId=15, desc=非数字, params={"member_id":"${member_id}","amount":"dddd"}, apiId=3, expectData=[{"value":2,"expression":"$.code"}], sql=null]]
    替换后的params:{"mobile_phone":"15000146880","pwd":""}
    替换后的SQLparams :
    输出响应体:{"code":1,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:true
    sql断言结果:true
    替换后的params:{"mobile_phone":"","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":1,"msg":"手机号为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:true
    sql断言结果:true
    替换后的params:{"mobile_phone":"187","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"无效的手机格式","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    sql断言结果:true
    替换后的params:{"mobile_phone":"15000146880","pwd":"&&&&"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"密码格式为8到16位","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:true
    sql断言结果:true
    替换后的params:{"mobile_phone":"15000146880","pwd":"123456789"}
    替换后的SQLparams :select count(*) from  member  where mobile_phone=15000146880
    输出响应体:{"code":0,"msg":"OK","data":{"id":100051820,"reg_name":"小柠檬","mobile_phone":"15000146880"},"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    期望值:0,实际值:0,断言结果:true
    数据响应断言结果:true
    数据库断言结果:true
    sql断言结果:true
    替换后的params:{"mobile_phone":"15000146880","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    sql断言结果:true
    替换后的params:{"mobile_phone":"15000146880","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    sql断言结果:true
    替换后的params:{"mobile_phone":"15000146880","pwd":"123456789"}
    替换后的SQLparams :
    输出响应体:{"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}
    数据响应断言结果:false
    sql断言结果:true
    PASSED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=1, desc=传手机号,不传密码, params={"mobile_phone":"15000146880","pwd":""}, apiId=1, expectData={"code":1,"msg":"密码为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=])
            测试注册接口
    PASSED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=2, desc=不传手机号,传密码, params={"mobile_phone":"","pwd":"123456789"}, apiId=1, expectData={"code":1,"msg":"手机号为空","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=])
            测试注册接口
    PASSED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=4, desc=合格的手机号,不合格密码, params={"mobile_phone":"15000146880","pwd":"&&&&"}, apiId=1, expectData={"code":2,"msg":"密码格式为8到16位","data":null,"copyright":"Copyright 柠檬班 © 2017-2020 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=])
            测试注册接口
    PASSED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=5, desc=合格的手机号,合格密码, params={"mobile_phone":"15000146880","pwd":"123456789"}, apiId=1, expectData=[{"value":0,"expression":"$.code"}], sql=select count(*) from  member  where mobile_phone=15000146880])
            测试注册接口
    FAILED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=3, desc=不合格的手机号, params={"mobile_phone":"187","pwd":"123456789"}, apiId=1, expectData={"code":2,"msg":"无效的手机格式","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=])
            测试注册接口
    java.lang.AssertionError: expected [pass] but found [fail]
        at org.testng.Assert.fail(Assert.java:94)
        at org.testng.Assert.failNotEquals(Assert.java:494)
        at org.testng.Assert.assertEquals(Assert.java:123)
        at org.testng.Assert.assertEquals(Assert.java:176)
        at org.testng.Assert.assertEquals(Assert.java:186)
        at com.lemon.cases.RegisterCase.testRegister(RegisterCase.java:68)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
        at org.testng.TestRunner.privateRun(TestRunner.java:767)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
        at org.testng.SuiteRunner.run(SuiteRunner.java:254)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
    
    FAILED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=6, desc=重复以上的手机号-密码, params={"mobile_phone":"15000146880","pwd":"123456789"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=])
            测试注册接口
    java.lang.AssertionError: expected [pass] but found [fail]
        at org.testng.Assert.fail(Assert.java:94)
        at org.testng.Assert.failNotEquals(Assert.java:494)
        at org.testng.Assert.assertEquals(Assert.java:123)
        at org.testng.Assert.assertEquals(Assert.java:176)
        at org.testng.Assert.assertEquals(Assert.java:186)
        at com.lemon.cases.RegisterCase.testRegister(RegisterCase.java:68)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
        at org.testng.TestRunner.privateRun(TestRunner.java:767)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
        at org.testng.SuiteRunner.run(SuiteRunner.java:254)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
    
    FAILED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=7, desc=重复以上的手机号-密码, params={"mobile_phone":"15000146880","pwd":"123456789"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=])
            测试注册接口
    java.lang.AssertionError: expected [pass] but found [fail]
        at org.testng.Assert.fail(Assert.java:94)
        at org.testng.Assert.failNotEquals(Assert.java:494)
        at org.testng.Assert.assertEquals(Assert.java:123)
        at org.testng.Assert.assertEquals(Assert.java:176)
        at org.testng.Assert.assertEquals(Assert.java:186)
        at com.lemon.cases.RegisterCase.testRegister(RegisterCase.java:68)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
        at org.testng.TestRunner.privateRun(TestRunner.java:767)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
        at org.testng.SuiteRunner.run(SuiteRunner.java:254)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
    
    FAILED: testRegister(Api [id=1, name=register, type=post, url=http://api.lemonban.com/futureloan/member/register, contentType=json], Cases [caseId=8, desc=重复以上的手机号-密码, params={"mobile_phone":"15000146880","pwd":"123456789"}, apiId=1, expectData={"code":2,"msg":"账号已存在","data":null,"copyright":"Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved"}, sql=])
            测试注册接口
    java.lang.AssertionError: expected [pass] but found [fail]
        at org.testng.Assert.fail(Assert.java:94)
        at org.testng.Assert.failNotEquals(Assert.java:494)
        at org.testng.Assert.assertEquals(Assert.java:123)
        at org.testng.Assert.assertEquals(Assert.java:176)
        at org.testng.Assert.assertEquals(Assert.java:186)
        at com.lemon.cases.RegisterCase.testRegister(RegisterCase.java:68)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
        at org.testng.TestRunner.privateRun(TestRunner.java:767)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
        at org.testng.SuiteRunner.run(SuiteRunner.java:254)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
    
    
    ===============================================
        Default test
        Tests run: 8, Failures: 4, Skips: 0
    ===============================================
    
    
    ===============================================
    Default suite
    Total tests run: 8, Failures: 4, Skips: 0
    ===============================================
    
    [TestNG] Time taken by org.testng.reporters.EmailableReporter2@46f699d5: 49 ms
    [TestNG] Time taken by org.testng.reporters.XMLReporter@10fde30a: 12 ms
    [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 6 ms
    [TestNG] Time taken by org.testng.reporters.jq.Main@2cac4385: 149 ms
    [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@2c3dec30: 52 ms
    [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@659eef7: 9 ms
    Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
    
    

    上述可以看到抛出4个异常,如果不用testng自带的断言方法,是不会抛出异常的,显示的就是 Failure 0,testng自带的统计报告也是通过代码报错来统计的,如下图,不过不用自带的断言方法,显示的都是打勾


    image.png

    执行clean 重新生成报表,打开报表如下:执行8个case,4个通过,4个失败

    image.png

    excel显示的也是四个fail

    image.png

    总结:

    1. 导入allure坐标
    2. 导入surefire插件
    3. 运行 maven clean ,maven test ->生成报表数据
    4. 运行: io.qameta.allure:allure-maven:serve启动报表服务器
      5.注解加说明
      1. @test(dataProvider="data", description="测试登录接口")
      2. @Step("回写excel")详细描写自动化程序的每个执行步骤

    相关文章

      网友评论

          本文标题:2020-05-19Api_ Log4j+Allure

          本文链接:https://www.haomeiwen.com/subject/hrjvohtx.html