Este conteúdo não está disponível no idioma selecionado.
Chapter 5. Applying interceptors to tests
Quarkus tests are full CDI beans, so you can apply CDI interceptors as you would normally. For example, if you want a test method to run within the context of a transaction, you can apply the @Transactional annotation to the method. You can also create your own test stereotypes.
Procedure
Add the
quarkus-narayana-jtadependency to yourpom.xmlfile:<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-narayana-jta</artifactId> </dependency>Make sure the
TransactionalQuarkusTest.javaincludes the following import statements:package org.acme.quickstart; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.enterprise.inject.Stereotype; import javax.transaction.Transactional; import io.quarkus.test.junit.QuarkusTest;Create the
@TransactionalQuarkusTestannotation:@QuarkusTest @Stereotype @Transactional @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface TransactionalQuarkusTest { }Apply this annotation to a test class where it will behave as if you applied both the
@QuarkusTestand@Transactionalannotations:@TransactionalQuarkusTest public class TestStereotypeTestCase { @Inject UserTransaction userTransaction; @Test public void testUserTransaction() throws Exception { Assertions.assertEquals(Status.STATUS_ACTIVE, userTransaction.getStatus()); } }This is a simple test that evaluates the greeting service directly without using HTTP.