Giter Club home page Giter Club logo

log4reports's Introduction

Log4Reports

框架说明(Description):

It's a framework of automation testing log and report

框架详情及使用方式可以参考博客(more details):http://www.jianshu.com/p/2c3fd46e2357

1、框架详情及使用方式可以参考博客(more details):http://www.jianshu.com/p/2c3fd46e2357

2、框架jar包:

version 1.0.0: Log4Reports_1.0.0.jar

使用示例(Demo):

1> 创建测试类继承Log4Reports框架的BaseCase类,并实现initConfig()方法:
public class TestCase1 extends **BaseCase** {
    ……
    //实现BaseCase的initConfig()方法
    @Override
    public void initConfig() {
        // TODO Auto-generated method stub
        logConfig = new LogConfig.Builder("\\\\172.0.0.1\\SharedFolder") //设置共享目录
        .setLogType(0)      //设置日志类型
        .setRetryTimes(1) //设置失败重跑次数
        .setSmtpHost("smtp.163.com") //设置发送邮箱的smtp host
        .setSender("[email protected]") //设置发送邮箱的账号
        .setSendPassword("123456) //设置发送邮箱的账号密码
        .setReceivers("[email protected];[email protected]") //邮件接收者账号,多个账号用分号隔开
        .setSubject("Test Log4Reports") //邮件主题
        .build();
        System.out.println("init log config finished.");
    }
}
2> 如果需要使用TestNG的@BeforeClass(BaseCase中使用的注解包括:@BeforeSuite、@AfterSuite、@BeforeClass、@AfterClass、@BeforeMethod、@AfterMethod 这6个)等注解时,需要覆写这些方法时先调用父类对应方法:
    @BeforeClass
    public void beforeClass() {
        super.beforeClass();
        /** 下面实现你自己的逻辑 **/
    }
        @AfterClass
    public void afterClass(){
        super.afterClass();
        /** 下面实现你自己的逻辑 **/
    }
    @AfterMethod
    public void afterMethod(ITestResult result) {
        super.afterMethod(result);
        /** 下面实现你自己的逻辑 **/
    }

    /** 不是上述的6个注解,不用调用父类的方法 **/
3>使用@Test注解编写测试方法:
public class TestCase1 extends BaseCase{
    private int flag = 0;

    @BeforeClass
    public void beforeClass() {
        super.beforeClass();
        flag = 1;
    }

    @AfterMethod
    public void afterMethod(ITestResult result) {
        super.afterMethod(result);
        flag = flag >1 ? 1 : flag;
    }

    @Test
    public void test(){
        if(assertEquals(flag, 1, true)){
            flag ++;
        }
        Log.info("this is info log");
        Log.pass("this is pass log");    
    }

    @Test
    public void test2(){
        if(assertEquals(flag, 2, true)){
            flag --;
        }
        Log.info("this is info log----A");
        Log.error("this is error log---B");
        Log.warn("this is warning log----C");
        Log.pass("this is pass log----D");
        Log.fail("this is fail log----E");
    }

    @Override
    public void initConfig() {
        // TODO Auto-generated method stub
        logConfig = new LogConfig.Builder("\\\\172.0.0.1\\SharedFolder")
        .setLogType(0)
        .setRetryTimes(1)
        .setSmtpHost("smtp.163.com")
        .setSender("[email protected]")
        .setSendPassword("123456")
        .setReceivers("[email protected]")
        .setSubject("Test Log4Reports")
        .build();
        System.out.println("init log config finished.");
    }
}

效果(Show):

image

image

image

log4reports's People

Contributors

alanyangs avatar

Watchers

James Cloos avatar testX avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.