Skip to content

@QuarkusTest Inheritance #43136

Open
Open

Description

Description

As also described in this StackOverflow post from two years ago: https://stackoverflow.com/questions/71957071/quarkus-tests-inheritance-not-allowed

It would be nice, if the annotation @QuarkusTest would be annotated with @Inherited, so it would not be nescessarry to add the annotation to all Test classes which use Quarkus.

I tried declaring a Meta annotation like mentioned in the post the following way, which did not work:

@Inherited
@QuarkusTest
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface IntegrationTest {
}

And adding an abstract class for all integration tests for example:

@IntegrationTest
@Tag("integration")
public abstract class AbstractIntegrationTest extends AbstractTest {
}

Actual test class:

@TestHTTPEndpoint(TestSvc.class)
public class TestIntegrationTests extends AbstractIntegrationTest {

	@Test
	public void testGet() {
		when().get("/1234567-8")
				.then()
				.statusCode(200)
				.body(is(notNullValue()));
	}
}

The actual test then fails with following mesage:

org.junit.jupiter.api.extension.TestInstantiationException: Failed to create test instance

	at io.quarkus.test.junit.QuarkusTestExtension.initTestState(QuarkusTestExtension.java:780)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:746)
	at java.base/java.util.Optional.orElseGet(Optional.java:364)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at io.quarkus.runner.bootstrap.RunningQuarkusApplicationImpl.instance(RunningQuarkusApplicationImpl.java:90)
	at io.quarkus.test.junit.QuarkusTestExtension.createActualTestInstance(QuarkusTestExtension.java:786)
	at io.quarkus.test.junit.QuarkusTestExtension.initTestState(QuarkusTestExtension.java:774)
	... 4 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at io.quarkus.runner.bootstrap.RunningQuarkusApplicationImpl.instance(RunningQuarkusApplicationImpl.java:88)
	... 6 more
Caused by: jakarta.enterprise.inject.UnsatisfiedResolutionException: No bean found for required type [class com.test.TestIntegrationTest] and qualifiers [[]]
	at io.quarkus.arc.impl.InstanceImpl.bean(InstanceImpl.java:288)
	at io.quarkus.arc.impl.InstanceImpl.getInternal(InstanceImpl.java:309)
	at io.quarkus.arc.impl.InstanceImpl.get(InstanceImpl.java:190)
	... 8 more

Edit: Adding a @QuarkusTest to the actual Test class fixes it and the test passes, but this has to be done for all test classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions