ClassCastException at running JUnit-Test with Annocation @QuarkusTest
See original GitHub issueDescribe the bug
I have a junit parameterized test (written in Kotlin) that is annotated as a @QuarkusTest. My IDE can compile my test, but at the runtime i get a ClassCastException:
java.lang.ClassCastException: class io.restassured.internal.ValidatableResponseImpl cannot be cast to class io.restassured.response.ValidatableResponse (io.restassured.internal.ValidatableResponseImpl is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @74960bfa; io.restassured.response.ValidatableResponse is in unnamed module of loader 'app')
My Test Class:
@QuarkusTest
@QuarkusTestResource(TestResource::class)
class ResourcesTest {
@ParameterizedTest(name = "{0}")
@MethodSource("validData")
fun `should succeed when input valid`(requestBody: String, responseBodyValidator: (resp: ValidatableResponse) -> Unit) {
val assertThat = given()
.config(
RestAssured.config()
.encoderConfig(encoderConfig().encodeContentTypeAs("application/graphql", ContentType.TEXT))
)
.body(requestBody)
.headers(mapOf(HttpHeader.USERNAME to "foobar", HttpHeader.TENANT_ID to "1"))
.contentType("application/graphql")
.post("/graphql")
.then()
.assertThat()
assertThat
.contentType(ContentType.JSON)
.statusCode(200)
responseBodyValidator.invoke(assertThat)
}
companion object {
@JvmStatic
fun validData(): List<Arguments> {
val parameters = ArrayList<Arguments>()
parameters.add(
Arguments.of(
VALID_INSERT_HUMAN_REQUEST,
fun(resp: ValidatableResponse): Unit { resp.body("data.insertHumanResource.firstName", Matchers.`is`(FIRST_NAME)) })
)
return parameters
}
}
}
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Output of uname -a or ver
No response
Output of java -version
openjdk version “11.0.10” 2021-01-19 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.2.3.Final
Build tool (ie. output of mvnw --version or gradlew --version)
apache maven 3.8.1
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
This is a known issue with parameterised tests.
Because JUnit does not directly have support alternate class loaders we have to basically proxy the requests into a new class loader, so for parameterized tests we attempt to clone the parameters into the new class loader, which is not always possible.
If https://github.com/junit-team/junit5/issues/2579 is resolved we should be able to fix this.
If somebody will face the same issue with
@MethodSourceI found the workaround:instead of
@MethodSourceI use the
@EnumSource