Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kotlin-reporter-junit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/logs/
**/target/
51 changes: 51 additions & 0 deletions kotlin-reporter-junit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Kotlin reporter integration with JUnit5

## Overview

This simple demo shows how Testomat.io Kotlin reporter works in your project.

- Some will fail on purpose and other will be disabled for demo.

## Installation

1. Clone the repository

```sh
git clone https://github.com/testomatio/examples.git
```
2. Change the directory

```sh
cd Kotlin-reporter-junit
```
3. Install dependencies with test skip

```sh
mvn clean install -DskipTests
```


## Configurations

**By default, the library runs with properties default values except `testomatio.api.key` and `testomatio.listening`**

![properties image](img/properties.png)

Add your project API key to the `testomatio.properties` file ad `testomatio.api.key`

## Run

Run tests with

```bash
mvn test -Dtestomatio.api.key=tstmt_key #if you did not provide it in the `testomatio.properties` file
```

where `tstmt_key` is your Testomat.io key from a particular project.

As a result, you will see a run report in your Project tab -> Runs on Testomat.io.

<div align="center">
<img src="img/runReport.png" alt="demo report result png" style="max-width: 70%; max-height: 420px;">
</div>

Binary file added kotlin-reporter-junit/img/properties.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kotlin-reporter-junit/img/runReport.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions kotlin-reporter-junit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testomat</groupId>
<artifactId>kotlin-reporter-junit</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
</properties>

<repositories>
<repository>
<id>mavenCentral</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>

<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>2.0.20</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>MainKt</mainClass>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>2.0.20</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.5.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>2.0.20</version>
</dependency>
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-junit</artifactId>
<version>0.13.1</version>
</dependency>
</dependencies>

</project>
4 changes: 4 additions & 0 deletions kotlin-reporter-junit/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.testomat

fun main() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#This line is the mandatory
junit.jupiter.extensions.autodetection.enabled = true

junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.mode.classes.default=concurrent
junit.jupiter.execution.parallel.config.strategy=dynamic
junit.jupiter.execution.parallel.config.dynamic.factor=1.0
100 changes: 100 additions & 0 deletions kotlin-reporter-junit/src/test/kotlin/tests/AdvancedApiTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package tests

import io.restassured.RestAssured.*
import io.restassured.http.ContentType
import org.hamcrest.Matchers.*
import org.junit.jupiter.api.Test
import java.util.concurrent.TimeUnit
import io.testomat.core.annotation.TestId

class AdvancedApiTests : BaseTest() {

@Test
@TestId("e2c71562")
fun `response should have expected headers`() {
get("/posts/1")
.then()
.statusCode(200)
.header("Content-Type", containsString("application/json"))
.header("X-Ratelimit-Limit", notNullValue())
.header("X-Ratelimit-Remaining", notNullValue())
}

@Test
@TestId("701867b2")
fun `response time should be acceptable`() {
get("/posts")
.then()
.statusCode(200)
.time(lessThan(5000L), TimeUnit.MILLISECONDS)
}

@Test
@TestId("5a80e045")
fun `extract and reuse response data`() {
val title: String = get("/posts/1")
.then()
.statusCode(200)
.extract()
.path("title")

val userId: Int = get("/posts/1")
.then()
.statusCode(200)
.extract()
.path("userId")

val titles: List<String> = given()
.queryParam("userId", userId)
.`when`()
.get("/posts")
.then()
.statusCode(200)
.extract()
.path("title")

assert(titles.isNotEmpty())
assert(titles.all { it.isNotEmpty() })
}

@Test
@TestId("8f4f9513")
fun `response body as string and parse`() {
val body: String = get("/posts/1")
.then()
.statusCode(200)
.extract()
.asString()

assert(body.contains("sunt aut facere"))
assert(body.startsWith("{"))
}

@Test
@TestId("5c2433ea")
fun `get specific field from list response`() {
val names: List<String> = get("/users")
.then()
.statusCode(200)
.extract()
.path("name")

assert(names.contains("Leanne Graham"))
assert(names.size == 10)
}

@Test
@TestId("564a873d")
fun `patch should work via override header`() {
val payload = """{"title":"patched-title"}"""
given()
.contentType(ContentType.JSON)
.header("X-HTTP-Method-Override", "PATCH")
.body(payload)
.`when`()
.post("/posts/1")
.then()
.statusCode(200)
.body("title", equalTo("patched-title"))
}
}
80 changes: 80 additions & 0 deletions kotlin-reporter-junit/src/test/kotlin/tests/AlbumsPhotosTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package tests

import io.restassured.RestAssured.*
import org.hamcrest.Matchers.*
import org.junit.jupiter.api.Test
import io.testomat.core.annotation.TestId

class AlbumsPhotosTests : BaseTest() {

@Test
@TestId("baeaa69f")
fun `GET albums returns list`() {
get("/albums")
.then()
.statusCode(200)
.body("size()", greaterThan(0))
.body("[0].userId", notNullValue())
.body("[0].id", notNullValue())
.body("[0].title", notNullValue())
}

@Test
@TestId("992b5069")
fun `GET album by id`() {
get("/albums/1")
.then()
.statusCode(200)
.body("userId", equalTo(1))
.body("title", equalTo("quidem molestiae enim"))
}

@Test
@TestId("7e8fe52c")
fun `GET photos for album`() {
get("/albums/1/photos")
.then()
.statusCode(200)
.body("size()", greaterThan(0))
.body("[0].albumId", equalTo(1))
.body("[0].title", notNullValue())
.body("[0].url", notNullValue())
.body("[0].thumbnailUrl", notNullValue())
}

@Test
@TestId("b67876bb")
fun `GET photos endpoint`() {
get("/photos")
.then()
.statusCode(200)
.body("size()", greaterThan(0))
.body("[0].albumId", notNullValue())
.body("[0].url", containsString("https://"))
}

@Test
@TestId("779ccfcd")
fun `GET photo by id`() {
get("/photos/1")
.then()
.statusCode(200)
.body("id", equalTo(1))
.body("albumId", equalTo(1))
.body("title", notNullValue())
.body("url", notNullValue())
}

@Test
@TestId("581d506a")
fun `GET albums by userId`() {
given()
.queryParam("userId", 1)
.`when`()
.get("/albums")
.then()
.statusCode(200)
.body("size()", greaterThan(0))
.body("userId", everyItem(equalTo(1)))
}
}
14 changes: 14 additions & 0 deletions kotlin-reporter-junit/src/test/kotlin/tests/BaseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tests

import io.restassured.RestAssured.baseURI
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.TestInstance

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class BaseTest {

@BeforeAll
fun setup() {
baseURI = "https://jsonplaceholder.typicode.com"
}
}
Loading
Loading