Browse Source

JUnit5 parameterized tests don't work correctly with arquillian (#5833)

* JUnit5 parameterized tests don't work correctly with arquillian

* disable test on java 17
Lauri Tulmin 2 years ago
parent
commit
1f9c1c1b5f

+ 14 - 5
instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/src/main/java/AbstractArquillianRestTest.java

@@ -18,11 +18,10 @@ import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.asset.EmptyAsset;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestInstance;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.api.extension.RegisterExtension;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
 import test.CdiRestResource;
 import test.EjbRestResource;
 import test.RestApplication;
@@ -52,9 +51,19 @@ public abstract class AbstractArquillianRestTest {
     return url.getPath();
   }
 
-  @ParameterizedTest
-  @CsvSource({"rest-app/cdiHello, CdiRestResource", "rest-app/ejbHello, EjbRestResource"})
-  public void testHelloRequest(String path, String className) {
+  @Test
+  public void testHelloCdiRestResource() {
+    testHelloRequest("rest-app/cdiHello", "CdiRestResource");
+  }
+
+  @Test
+  public void testHelloEjbRestResource() {
+    testHelloRequest("rest-app/ejbHello", "EjbRestResource");
+  }
+
+  // @ParameterizedTest doesn't work correctly with arquillian, all exceptions (assertion errors)
+  // thrown from the test method are ignored
+  private void testHelloRequest(String path, String className) {
     AggregatedHttpResponse response = client.get(url.resolve(path).toString()).aggregate().join();
 
     assertThat(response.status().code()).isEqualTo(200);

+ 6 - 1
instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-payara-testing/build.gradle.kts

@@ -2,12 +2,17 @@ plugins {
   id("otel.javaagent-testing")
 }
 
+otelJava {
+  // Test fails to start on java 17
+  maxJavaVersionForTests.set(JavaVersion.VERSION_11)
+}
+
 dependencies {
   testImplementation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-arquillian-testing"))
   testRuntimeOnly("fish.payara.arquillian:arquillian-payara-server-embedded:2.4.1")
   testRuntimeOnly("fish.payara.extras:payara-embedded-web:5.2021.2")
 
   testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
-  testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common:javaagent"))
+  testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-annotations:javaagent"))
   testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-jersey-2.0:javaagent"))
 }

+ 1 - 1
instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-tomee-testing/build.gradle.kts

@@ -10,6 +10,6 @@ dependencies {
   testRuntimeOnly("org.apache.tomee:tomee-jaxrs:8.0.6")
 
   testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
-  testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common:javaagent"))
+  testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-annotations:javaagent"))
   testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-cxf-3.2:javaagent"))
 }

+ 1 - 1
instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-wildfly-testing/build.gradle.kts

@@ -11,7 +11,7 @@ dependencies {
   testRuntimeOnly("org.wildfly.arquillian:wildfly-arquillian-container-embedded:2.2.0.Final")
 
   testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
-  testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common:javaagent"))
+  testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-annotations:javaagent"))
   testInstrumentation(project(":instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.0:javaagent"))
 
   // wildfly version used to run tests

+ 14 - 5
instrumentation/jaxws/jaxws-2.0-arquillian-testing/src/main/java/AbstractArquillianJaxWsTest.java

@@ -22,11 +22,10 @@ import org.jboss.shrinkwrap.api.asset.EmptyAsset;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestInstance;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.api.extension.RegisterExtension;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
 import test.EjbHelloServiceImpl;
 import test.HelloService;
 import test.HelloServiceImpl;
@@ -64,9 +63,19 @@ public abstract class AbstractArquillianJaxWsTest {
     return url.resolve(getServicePath(service)).toString();
   }
 
-  @ParameterizedTest
-  @ValueSource(strings = {"HelloService", "EjbHelloService"})
-  public void testHelloRequest(String service) {
+  @Test
+  public void testHelloService() {
+    testHelloRequest("HelloService");
+  }
+
+  @Test
+  public void testEjbHelloService() {
+    testHelloRequest("EjbHelloService");
+  }
+
+  // @ParameterizedTest doesn't work correctly with arquillian, all exceptions (assertion errors)
+  // thrown from the test method are ignored
+  private void testHelloRequest(String service) {
     String soapMessage =
         "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:hel=\"http://opentelemetry.io/test/hello-web-service\">"
             + "   <soapenv:Header/>"