Este conteúdo não está disponível no idioma selecionado.
Chapter 4. Injection of CDI beans into tests
You can perform unit testing and test CDI beans directly. Quarkus enables you to inject CDI beans into your tests through the @Inject annotation. In fact, tests in Quarkus are full CDI beans so you can use the complete CDI functionality.
It is not possible to use injection with native tests.
Procedure
Create the
GreetingServiceTest.javafile with the following content:package org.acme.quickstart; import javax.inject.Inject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest public class GreetingServiceTest { @Inject1 GreetingService service; @Test public void testGreetingService() { Assertions.assertEquals("hello Quarkus", service.greeting("Quarkus")); } }- 1
- The
GreetingServicebean will be injected into the test.