0
votes

In Quarkus testing, one can easily use beans by annotating them with @Inject:

package com.test;

@QuarkusTest
class InjectionTest {

@Inject
SomeBean someBean;

@Test
void someTest() {
     // Testing logic, assertions and all
}

The "SomeBean":

package com.test;

@ApplicationScoped
public class SomeBean {
}

Unfortunately this results in an error when using a multiple modular setup. An example project for such a setup can be found here: https://github.com/lssoares/multi-maven-quarkus To reproduce, just try to inject any bean into any of the tests.

The error thrown will look something like this:

Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type com.test.SomeBean and qualifiers [@Default]
    - java member: com.test.InjectionTest#someBean

The injection of this bean goes perfectly well when I run the application. Why does Quarkus have the bean in normal context, but not in test context? Why does this problem specifically occur in a multi-modular setup? And more importantly, how to fix this?

1

1 Answers

0
votes

I was using the (at that time) latest version of Quarkus: 1.10.5.Final. After upgrading to the present latest version: 1.11.0.Final the problem is resolved.

Old:

  <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-universe-bom</artifactId>
    <version>1.10.5.Final</version>
    <type>pom</type>
    <scope>import</scope>
  </dependency>

  <plugin>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-maven-plugin</artifactId>
      <version>1.10.5.Final</version>
      <executions>
        <execution>
          <goals>
            <goal>build</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

New:

  <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-universe-bom</artifactId>
    <version>1.11.0.Final</version>
    <type>pom</type>
    <scope>import</scope>
  </dependency>

  <plugin>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-maven-plugin</artifactId>
      <version>1.11.0.Final</version>
      <executions>
        <execution>
          <goals>
            <goal>build</goal>
          </goals>
        </execution>
      </executions>
    </plugin>