Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saksmt/ktest
kTest - integration/acceptance/system/whatever test oriented modular test framework in Kotlin
https://github.com/saksmt/ktest
acceptance-testing integration-testing kotlin system-testing test test-automation test-framework testing testing-framework tests
Last synced: about 2 months ago
JSON representation
kTest - integration/acceptance/system/whatever test oriented modular test framework in Kotlin
- Host: GitHub
- URL: https://github.com/saksmt/ktest
- Owner: saksmt
- License: mit
- Created: 2017-12-21T16:12:18.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2019-01-31T10:33:01.000Z (almost 6 years ago)
- Last Synced: 2024-01-27T16:20:20.808Z (11 months ago)
- Topics: acceptance-testing, integration-testing, kotlin, system-testing, test, test-automation, test-framework, testing, testing-framework, tests
- Language: Kotlin
- Size: 364 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# kTest
[![CircleCI](https://img.shields.io/circleci/project/github/saksmt/ktest.svg?style=flat-square)](https://circleci.com/gh/saksmt/ktest) ![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/oss.sonatype.org/content/repositories/releases/run/smt/ktest/ktest-api/maven-metadata.xml.svg?style=flat-square)
kTest is integration / acceptance / system / any other non-unit test oriented modular test framework in Kotlin.
Inspired by [kotlintest](https://github.com/kotlintest/kotlintest), [specs2](https://github.com/etorreborre/specs2) and martians.## Usage
### [Styling your test](doc/core/api.md)
[//]: # (no_check)
```kotlin
object MyTestSpecification : BehaviorSpec({
given("some service") {
`when`("executing it's API") {
then("it should work correctly") {
// test body...
}
}
}
})
```### [Performing simple HTTP](doc/integration/rest-assured/rest.md)
[//]: # (no_check)
```kotlin
fun makeMyHttp(): List {
return rest["my-backend"] {
using(url) {
agreements / param("id") / accounts
} execute {
GET(pathParam(123), header("Accept", "application/json"))
}
}
}
```### [Working with JSON](doc/integration/jackson.md)
[//]: # (no_check)
```kotlin
fun loadAccounts(resourcePath: String) =
resourcePath.loadAsJson { list(map()) }.also {
println(it.dump()) // pretty-printing pseudo-logging
}
```### [Matching over JSON](doc/integration/json-matcher.md)
[//]: # (no_check)
```kotlin
fun compareMyJsons(expected: JsonNode, actual: JsonNode) {
with(JsonNodeMatchers) {
assertThat(actual, isIdenticalTo(expected).bySubtree {
// comparing only meaningful nodes
"accounts[*]" {
+ "id"
+ "accountNumber"
"owner" {
+ "id"
+ "name"
}
}
})
}
}
```### [Searching over JSON](doc/integration/jsonpath.md)
*Powered by [JSONPath](https://github.com/json-path/JsonPath)*
[//]: # (no_check)
```kotlin
fun allIdsNearAccountNumbers(jp: DocumentContext) =
jp select "id" where {
"accountNumber".exists()
} castTo { list() }
```### [Accessing database](doc/integration/spring-jdbc.md)
[//]: # (no_check)
```kotlin
fun getAccounts(activeOn: Date) =
"my-database".db {
select("""
| SELECT * FROM accounts
| WHERE
| close_date is NULL
| OR close_date < :activeOn
""".trimMargin()) {
parameter("activeOn", activeOn)
}.asList()
}
```### [REST specification](doc/integration/rest-assured/rest-test.md)
[//]: # (no_check)
```kotlin
object MyTest : SimpleSpec({
suite("my service suite") {
restTest(name = { "${it.method} accounts" }) {
url { agreements / accounts }
GET(queryParam("name", "%"))
POST(body("name", "%")) { it / search }
expect { response: DocumentContext ->
// do some check
}
}
}
})
```### [Configuring reporting engine](doc/integration/allure.md)
*Reporting powered by excellent [Allure](http://allure.qatools.ru)*
[//]: # (no_check)
```kotlin
object MyTest : AllureSpec({
feature("some feature", metaInfo = {
blocker()
}) {
story("true story", metaInfo = {
issue("PROJ-111")
}) {
case("my case", metaInfo = {
description("my description")
}) {
// test body...
}
}
}
})
```### Putting it all together
[//]: # (no_check)
```kotlin
object AccountByCustomerRestApiSpec : AllureSpec({
beforeAll {
rest["backend"] {
using(url) {
`internal` / caches
} execute {
DELETE(queryParam("force", "true"))
}
}
}epic("Search") {
feature("Account by customer search") {
story("Single criteria search") {
val testTable = table(
header("criteriaName", "criteriaValue", "expectedJsonName"),
row("billing", ">100", "richAccounts.json"),
row("region", "Central", "centralRegionAccounts.json"),
row("validTill", ">${LocalDate.now().format(DateTimeFormatter.ISO_DATE)}", "activeAccounts.json")
)
// should be generated right before test
val myGeneratedCustomer: Customer = testData["customer.json"]
forAll(testTable) { criteriaName, criteriaValue, expectedJsonName ->
val criteria = mapOf(
criteriaName, criteriaValue
)
restTest(name = { "Search account by \"$criteriaName\": ${it.method}" }, metaData = {
category()
flaky()
}) {
url { customers / param("customerId") / accounts }
GET(queryParams(criteria), pathParam("customerId", myGeneratedCustomer.id))
POST(body(criteria), pathParam("customerId", myGeneratedCustomer.id))
expect { response: DocumentContext ->
with(DocumentContextMatchers) {
assertThat(response, matches(expectedJsonName.loadAsJsonPath()).afterRemovalOfSubtree {
"account[].metaData" {
+ "date"
+ "IP"
}
})
}
}
}
}
}
}
}
})
```For more see [docs](doc/README.md) and [samples](sample)
## Download
You can use [dependency management](doc/pom.md)
### Gradle
```groovy
compile 'run.smt.ktest:ktest-api'
compile 'run.smt.ktest:ktest-config'
compile 'run.smt.ktest:ktest-util'
compile 'run.smt.ktest:ktest-runner-junit4'
compile 'run.smt.ktest:ktest-allure'
compile 'run.smt.ktest:ktest-jackson'
compile 'run.smt.ktest:ktest-json-matchers'
compile 'run.smt.ktest:ktest-jsonpath'
compile 'run.smt.ktest:ktest-db'
compile 'run.smt.ktest:ktest-rest'
compile 'run.smt.ktest:ktest-resttest'
```### Maven
```xml
run.smt.ktest
ktest-apirun.smt.ktest
ktest-configrun.smt.ktest
ktest-utilrun.smt.ktest
ktest-runner-junit4run.smt.ktest
ktest-allurerun.smt.ktest
ktest-jacksonrun.smt.ktest
ktest-json-matchersrun.smt.ktest
ktest-jsonpathrun.smt.ktest
ktest-dbrun.smt.ktest
ktest-restrun.smt.ktest
ktest-resttest```
## License
All source code is licensed under [MIT license](LICENSE)