-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
area/arcIssue related to ARC (dependency injection)Issue related to ARC (dependency injection)kind/bugSomething isn't workingSomething isn't working
Milestone
Description
Hello @mkouba,
This is in regards to our conversation from Zulip.
Beans injected into a test are automatically removed.
I have a service:
@ApplicationScoped
public class TestService {
}
And a test:
@QuarkusTest
public class GreetingResourceTest {
@Inject
TestService ts;
@Test
void test_lookupService() {
Assertions.assertThat(ts).isNotNull();
}
}
Since TestService
has bean defining annotation it is automatically discovered. And since it's @Inject
-ed into test, it should not be autoremoved. But it's removed and test fails
The workarounds so far:
- Configure
quarkus.arc.remove-unused-beans=false
inapplication.preferences
- Add scope annotation on test, e.g.
@Singleton
:
@Singleton // this cause test pass
@QuarkusTest
public class GreetingResourceTest {
@Inject
TestService ts;
@Test
void test_lookupService() {
Assertions.assertThat(ts).isNotNull();
}
}
A failure log:
sarxos@sarxos-comp:~/workspace/getting-started$ mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.acme:getting-started >----------------------
[INFO] Building getting-started 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ getting-started ---
[INFO] Deleting /home/sarxos/workspace-2019/getting-started/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ getting-started ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ getting-started ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /home/sarxos/workspace-2019/getting-started/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ getting-started ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/sarxos/workspace-2019/getting-started/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ getting-started ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/sarxos/workspace-2019/getting-started/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ getting-started ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.acme.quickstart.GreetingResourceTest
2019-03-28 20:37:07,486 INFO [io.qua.dep.QuarkusAugmentor] (main) Beginning quarkus augmentation
2019-03-28 20:37:08,014 INFO [io.qua.dep.QuarkusAugmentor] (main) Quarkus augmentation completed in 528ms
2019-03-28 20:37:08,331 INFO [io.quarkus] (main) Quarkus 0.12.0 started in 0.300s. Listening on: http://[::]:8081
2019-03-28 20:37:08,331 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.902 s <<< FAILURE! - in org.acme.quickstart.GreetingResourceTest
[ERROR] test_lookupService Time elapsed: 0.01 s <<< ERROR!
org.junit.jupiter.api.extension.TestInstantiationException: TestInstanceFactory [io.quarkus.test.junit.QuarkusTestExtension] failed to instantiate test class [org.acme.quickstart.GreetingResourceTest]: Failed to inject field com.github.sarxos.abberwoult.cdi.TestService org.acme.quickstart.GreetingResourceTest.ts
Caused by: java.lang.RuntimeException: Failed to inject field com.github.sarxos.abberwoult.cdi.TestService org.acme.quickstart.GreetingResourceTest.ts
Caused by: java.lang.NullPointerException: Managed Bean [class com.github.sarxos.abberwoult.cdi.TestService] is null
2019-03-28 20:37:08,359 INFO [io.quarkus] (main) Quarkus stopped in 0.008s
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] GreetingResourceTest.test_lookupService » TestInstantiation TestInstanceFactor...
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.112 s
[INFO] Finished at: 2019-03-28T20:37:08+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.0:test (default-test) on project getting-started: There are test failures.
[ERROR]
[ERROR] Please refer to /home/sarxos/workspace-2019/getting-started/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Metadata
Metadata
Assignees
Labels
area/arcIssue related to ARC (dependency injection)Issue related to ARC (dependency injection)kind/bugSomething isn't workingSomething isn't working