Skip to content

Unable to inject TestHTTPResource field #46336

@jamesnetherton

Description

@jamesnetherton

Describe the bug

Relates to some Camel Quarkus test failures observed when testing against Quarkus 999-SNAPSHOT.

Likely caused by the recent change to TestHTTPResourceManager.java in c75ead2.

If you have a simple test class like this:

@QuarkusTest
@TestHTTPEndpoint(FooResource.class)
class FooTest {
    int bar = 1;

    @Test
    void testFoo() {

    }
}

It results in:

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

	at io.quarkus.test.junit.QuarkusTestExtension.initTestState(QuarkusTestExtension.java:767)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:733)
	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: Unable to inject TestHTTPResource field int org.acme.FooTest.bar as no provider exists for the type
	at io.quarkus.test.common.http.TestHTTPResourceManager.inject(TestHTTPResourceManager.java:69)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at io.quarkus.test.junit.QuarkusTestExtension.createActualTestInstance(QuarkusTestExtension.java:776)
	at io.quarkus.test.junit.QuarkusTestExtension.initTestState(QuarkusTestExtension.java:761)

The bar field is not annotated with TestHTTPEndpoint, so it should not be considered as a candidate for injection.

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

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions