19 Eylül 2021 Pazar

Arquillian

Giriş
Açıklaması şöyle
Arquillian is a container-agnostic integration testing framework for Jakarta EE.
Kullanılabilecek container'lar şöyle
- Jakarta EE applications deployed on an application server like Glassfish or JBoss
- Servlet containers deployed on Tomcat or Jetty
- Standalone containers
- OSGI containers
Maven
Örnek
Şu satırı dahil ederiz. Daha sonra kullanılacak container dependency'leri de eklenmelidir.
<!-- Arquillian 1.7.0 adds Jakarta EE 9 and JUnit 5 support--> <arquillian-bom.version>1.7.0.Alpha10</arquillian-bom.version> <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> <version>${arquillian-bom.version}</version> <scope>import</scope> <type>pom</type> </dependency> <dependency> <groupId>org.jboss.arquillian.junit5</groupId> <artifactId>arquillian-junit5-container</artifactId> <scope>test</scope> </dependency>
Kullanım
ShrinkWrap sınıfı döndüren bir metod yazılır. Bu metoda @Deployable anotasyonu eklenir.

Örnek
Şöyle yaparız
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

@ExtendWith(ArquillianExtension.class)
public class GreetingServiceTest {

  @Deployment
  public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
      .addClass(GreetingMessage.class)
      .addClass(GreetingService.class)
      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
  }

  @Inject
  GreetingService service;

  @Test
  @DisplayName("testing buildGreetingMessage")
  public void should_create_greeting() {

    var message = service.buildGreetingMessage("Jakarta EE");
    assertTrue(...);
  }
}

Hiç yorum yok:

Yorum Gönder