Skip to content

Spring Boot integration

If you want generated tests to run as Spring Boot tests, use the template generator and enable the template variable springBootTest.

Built-in RestAssured templates use customVariables.springBootTest to include Spring Boot annotations/imports.

Gradle example

openApiTestGenerator {
    generator.set("template")
    generatorOptions.putAll(
        mapOf(
            "templateSet" to "restassured-java",
            "templateVariables" to mapOf(
                "package" to "com.example.generated",
                "baseUrl" to "http://localhost:8080",
                "springBootTest" to true,
            ),
        )
    )
}

Samples

Spring Boot integration

The built-in RestAssured templates can emit Spring Boot test annotations when configured.

Enable @SpringBootTest

Set templateVariables.springBootTest=true.

Gradle

openApiTestGenerator {
    generator.set("template")
    generatorOptions.putAll(
        mapOf(
            "templateSet" to "restassured-java",
            "templateVariables" to mapOf(
                "springBootTest" to true,
                "baseUrl" to "http://localhost:8080",
            ),
        )
    )
}

Notes

  • The built-in templates use SpringBootTest.WebEnvironment.DEFINED_PORT. Configure your app under test accordingly.