How to get Cucumber Reports from Restassured Tests in a Kotlin Project

Viewed 234

In a Kotlin/Gradle Project, I would like to implement Integration Tests with Restassured and would like to generate a Cucumber report, after the test execution. Since the Cucumber, does not offer a native Kotlin implementation and the Cucumber-JVM must have been used; is it really possible to configure Restassured & Cucumber in a Kotlin project:

Here is my test class for Restassured:

package org.restassured.tests

//import org.hamcrest.Matchers.notNullValue
import io.cucumber.java8.En
import io.restassured.module.kotlin.extensions.Given
import io.restassured.module.kotlin.extensions.Then
import io.restassured.module.kotlin.extensions.When
import kotlinx.serialization.Required
import kotlinx.serialization.Serializable
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test
import org.restassured.BaseTest

class `Sample Tests` : BaseTest() {

    @Test
    fun `get first category`() {
        Given  {
            spec(requestSpecification)
        } When  {
            get("/categories/")
        } Then {
            statusCode(200)
            body("categories.name[0]", equalTo("Fresh"))
        }
    }

    @Test
    fun `get second category url`() {
        Given {
            spec(requestSpecification)
        } When {
            get("/categories/")
        } Then {
            statusCode(200)
            body("categories.category_url[1]", equalTo("/shop/categories/Fruits"))
        }
    }

}

@Serializable
data class Users(@Required val name: String, @Required val job: String)

And here is the separate Cucumber Class:

@file:Suppress("ClassName")

package org.restassured.tests

import io.cucumber.java8.En
import io.cucumber.junit.Cucumber
import io.cucumber.junit.CucumberOptions
import org.junit.runner.RunWith

@RunWith(Cucumber::class)
@CucumberOptions(
    features = ["src/test/resources/features"], publish = true)


class CucumberTest : En{
    init {
        Given("a category Fresh exists")  {
        }

        When("a user calls the API")  {
        }

        Then("the status code is 200 and the category retrieved") {
        }
    }
}

The problem here is, in the Cucumber class the syntax "Given, When, Then" are coming from Cucumber JVM; whereas in the first class, the same coming from restassured. Therefore I cannot link them in the same class. Any solution ideas?

Thanks in advance

0 Answers
Related