Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-1982

Each test case is launched 4 times in OSGi

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • None
    • Hide
      • Create a Test class using Arquillian

      import java.io.InputStream;
      import java.util.concurrent.TimeUnit;

      import junit.framework.Assert;

      import org.apache.commons.io.FileUtils;
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.arquillian.container.test.api.RunAsClient;
      import org.jboss.arquillian.drone.api.annotation.Drone;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.arquillian.junit.InSequence;
      import org.jboss.osgi.metadata.OSGiManifestBuilder;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.Asset;
      import org.jboss.shrinkwrap.api.spec.JavaArchive;
      import org.junit.After;
      import org.junit.Before;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import org.openqa.selenium.Alert;
      import org.openqa.selenium.By;
      import org.openqa.selenium.NoAlertPresentException;
      import org.openqa.selenium.NoSuchElementException;
      import org.openqa.selenium.OutputType;
      import org.openqa.selenium.TakesScreenshot;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.support.ui.WebDriverWait;
      import org.osgi.framework.Bundle;

      @RunAsClient
      @RunWith(Arquillian.class)
      public class SampleTest {

      @Drone
      protected WebDriver driver;

      protected StringBuffer verificationErrors = new StringBuffer();

      @Deployment(testable = false)
      public static JavaArchive createdeployment() {
      final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
      archive.setManifest(new Asset() {
      @Override
      public InputStream openStream()

      { OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance(); builder.addBundleSymbolicName(archive.getName()); builder.addBundleManifestVersion(2); builder.addImportPackages(Bundle.class); return builder.openStream(); }

      });
      return archive;
      }

      @Before
      public void setUp() throws Exception {
      }

      @Test
      @InSequence(1)
      public void firstTest()

      { System.out.println("firstTest()"); }

      @Test
      @InSequence(2)
      public void secondTest()

      { System.out.println("secondTest()"); }

      @After
      public void tearDown() throws Exception {
      String verificationErrorString = verificationErrors.toString();
      verificationErrors = new StringBuffer();
      if (!"".equals(verificationErrorString))

      { Assert.fail(verificationErrorString); }

      }
      }

      • Launch it in OSGi using with the plugin:
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-surefire-plugin</artifactId>
      Show
      Create a Test class using Arquillian import java.io.InputStream; import java.util.concurrent.TimeUnit; import junit.framework.Assert; import org.apache.commons.io.FileUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.drone.api.annotation.Drone; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.InSequence; import org.jboss.osgi.metadata.OSGiManifestBuilder; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.Asset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.NoAlertPresentException; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.WebDriverWait; import org.osgi.framework.Bundle; @RunAsClient @RunWith(Arquillian.class) public class SampleTest { @Drone protected WebDriver driver; protected StringBuffer verificationErrors = new StringBuffer(); @Deployment(testable = false) public static JavaArchive createdeployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar"); archive.setManifest(new Asset() { @Override public InputStream openStream() { OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance(); builder.addBundleSymbolicName(archive.getName()); builder.addBundleManifestVersion(2); builder.addImportPackages(Bundle.class); return builder.openStream(); } }); return archive; } @Before public void setUp() throws Exception { } @Test @InSequence(1) public void firstTest() { System.out.println("firstTest()"); } @Test @InSequence(2) public void secondTest() { System.out.println("secondTest()"); } @After public void tearDown() throws Exception { String verificationErrorString = verificationErrors.toString(); verificationErrors = new StringBuffer(); if (!"".equals(verificationErrorString)) { Assert.fail(verificationErrorString); } } } Launch it in OSGi using with the plugin: <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId>

      Each test is called 4 times on the following orders.

      @Before
      @Before
      @Test - firstTest
      @Test - firstTest
      @After
      @After
      @Before
      @Before
      @Test - firstTest
      @Test - firstTest
      @After
      @After
      -------------------------
      @Before
      @Before
      @Test - secondTest
      @Test - secondTest
      @After
      @After
      @Before
      @Before
      @Test - secondTest
      @Test - secondTest
      @After
      @After

      Note:
      ---------
      I tried without Drone -> same issue
      I tried without RunAsClient and without Deployment -> same issue
      The instance of the SampleTest Class is the same for each call of @Test method

              Unassigned Unassigned
              damien.vidal Damien Vidal (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: