Giter Club home page Giter Club logo

dbassert's Introduction

DbAssert

English README

DbAssert是一个简单、易使用的数据库校验工具,有完善的测试用例。

在做自动化测试过程中,做一些操作或者调用接口之后经常需要校验数据库,DbAssert正是为这个目的而设计的。

DbAssert具有以下特点:

  • 开箱即用
  • 校验类型丰富,除了明细数据也支持校验汇总数据,或者将返回结果作为list整体校验
  • 支持多种数据类型,并且兼容的格式可以自动转换
  • 支持分页查询,排序等
  • 支持重试
  • 支持延迟校验
  • 支持同时校验多种数据库
  • 报告易扩展

安装

maven项目:

pom文件增加以下依赖

<dependencies>
    <dependency>
        <groupId>com.github.cysong</groupId>
        <artifactId>dbassert</artifactId>
        <version>0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

基本使用

Connection conn=DriverManager.getConnection("jdbc:sqlite::memory:");
        DbAssert.create(conn)
        .table("person")
        .where("id",1)
        .col("name").as("person name").isEqual("alice")
        .run();

更多校验类型见Comparator ,更多的汇总方式见Aggregate

使用ConnectionFactory

DbAssert支持ConnectionFactory自动根据数据库配置文件创建连接,默认的数据配置文件为:database.yml,配置格式如下:

- key: sqlite
  url: 'jdbc:sqlite::memory:'
- key: mysql
  driver: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://localhost:3306/dbassert?useUnicode=true&characterEncoding=utf-8&useSSL=true
  username: dbassert
  password: dbassert

使用ConnectionFactory时需要这样调用DbAssert:

DbAssert.create(mysql)
        .table("person")
        .where("id",1)
        .col("name").as("person name").isEqual("alice")
        .run();

其中mysqldatabase.yml中配置的数据库key

高级用法

全局配置

如果要改变DbAssert的默认行为,可以修改全局配置(例如禁用重试):

DbAssertSetup.setup()
        .retry(false)
        .delay(3000);

自定义ConnectionFactory

如果默认的ConnectionFactory无法满足需求,也可以实现自己的ConnectionFactory,然后配置如下:

DbAssertSetup.setup()
        .factory(new MyConnectionFactory());

其中MyConnectionFactory是你自己的ConnectionFactory实现

集成报告

系统提供了报告接口Reporter,并提供了集成Allure报告的实现AllureReporter。Allure report的集成方式参见官方文档

要集成allure报告,首先你需要在自己的测试项目中集成Allure report,然后将AllureReporter拷贝到自己的项目下并配置:

DbAssertSetup.setup()
        .reporter(new AllureReporter());

如果AllureReporter无法满足需求,你需要实现自己的Reporter,并按照以上方式配置

更多用法参考测试用例:DbAssertTest.java

dbassert's People

Contributors

cysong avatar

Stargazers

 avatar

Watchers

 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.