1.0.0-RELEASE 是 ApiHug 一个小里程碑,最终ApiHug 解决方案包含了测试部分!

😆 教程:

  1. ApiHug101-Bilibili
  2. ApiHug101 Youtube

ApiHug - API design Copilot

ApiHug [1.0.0-RELEASE] - 2024-08-02

SDK Features

  • 全面支持DSL,类BDD, Contract 定义测试
  • 引入 wire 端 kolaTest 测试任务
  • 无缝集成所有现存测试解决方案(junit5 assertJ etc)

升级步骤

参考 apihug-demo/libs.versions.toml

  1. 升级版本: {PROJECT_ROOT}/gradle/libs.versions.toml 修改: apihug = "1.0.0-RELEASE"1.0.0-RELEASE+ 版本
  2. 添加 lib: springBootDependencies = { group = "org.springframework.boot", name = "spring-boot-dependencies", version.ref = "springBoot" }

由于尚在测验版本, 默认 kola 没有打开, 参考 build.gradle:

hopeWire {
    // others...
    kola = true
}

Sample

package contracts

import hope.kola.contract.Feature

Feature.make {
    priority 100
    name("Customer login place order and check balance logic")
    description("""Never judge the boss, as you may the real fool""")
    Scenario "001 Try login ", {
        Given {
            api("UserService", "Login")
        }
        When {
            json("""
                    
            """)
            body {
                set('name', "same")
                set('student.name', "blue")
                set('student.age', 22)
                set('student.weight', 123.3d)
                set('student.friends', "jake", "blue", "yellow")
                set('student.bigBaby', {
                    addStatement('res.setAge(12)')
                    addStatement('res.setBlogs($T.asList($S,$S))', Arrays.class, 'jake', 'same')
                })
                set('student.soreList', 12, 123, 45, Mocker.numberBetween(12, 34))
                set('json', Mocker.chineseName().name(), Mocker.cat().name(), Mocker.ip4(), regular("[a-z]"))
            }
        }
        And {
            stringAssert("user.address.zipCode", {
                isEqualTo("jake")
                isBase64()
                isAlphabetic()
                startsWithIgnoringCase("json")
            })
            bigDecimalAssert("user.salary", {
                isCloseTo(ofBigDecimal("1112.22"), offset(12))
                isGreaterThanOrEqualTo(ofBigDecimal("231312"))
            })
            booleanAssert("user.live", {
                isTrue()
            })

        }

    }
    Scenario "002 Place a order", {}
    Scenario "003 Check balance", {}
}

Copyright © 2024 ApiHug Inc.