Kola
Kola make your test life happier and colourful
⚠️请及时更新 SDK + IDEA插件保持先进⚠️
SDK Version
Plugin Version
Sine ApiHug [1.0.0-RELEASE] - 2024-08-02 关于Kola
kolaTest
测试任务参考 apihug-demo/libs.versions.toml
{your_project}/gradle/libs.versions.toml
修改: apihug = "xxx"
到 1.0.0-RELEASE
+ 版本springBootDependencies = { group = "org.springframework.boot", name = "spring-boot-dependencies", version.ref = "springBoot" }
⚠️ springBootDependencies
必须配置,否则 wire 编译会报错:
Could not get unknown property 'springBootDependencies' for extension 'libs' of type org.gradle.accessors.dm.LibrariesForLibs.
⚠️ 由于尚在测验版本, 默认 Kola 没有打开,你得修改 proto 模块的 build, 参考 build.gradle:
hopeWire {
// others...
kola = true
}
升级完SDK + Plugin 后(可能需要重启IDEA), Kola 是基于协议层的测试,所以和 proto 模块在一起;
文件模块 {your_project}/{proto_module}
目录 src/test/resourcs
:
├────────
│ junit-platform.properties ①
│
├─config
│ kola.groovy ②
│
└─kola
└─com
└─apihug
└─sample
test.groovy ③
junit-platform.properties
junit 配置文件 ①kola.groovy
环境配置文件 ②test.groovy
测试用例文件 ③完整 例子:
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.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", {}
}
Kick kolaTest
task, 测试:
./gradlwe.bat {proto_module}:kolaTest --stacktrace
groovy
feature 编译成测试用例