Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for running with TestNG while JUnit 4 is missing on classpath #155

Closed
wants to merge 2 commits into from

Conversation

sebastiankopp
Copy link

Apparently, using CDIUnit in combination with TestNG strictly requires JUnit 4 on the classpath.

When leaving out the dependency junit:junit:4.12 in my pom.xml, CDIUnit tests fail because the org.junit.runners.BlockJUnit4ClassRunner is missing:

java.lang.NoClassDefFoundError: org/junit/runners/BlockJUnit4ClassRunner
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at org.jglue.cdiunit.internal.WeldTestUrlDeployment.populateCdiClasspathSet(WeldTestUrlDeployment.java:405)
	at org.jglue.cdiunit.internal.WeldTestUrlDeployment.<init>(WeldTestUrlDeployment.java:97)
	at org.jglue.cdiunit.NgCdiRunner$1.createDeployment(NgCdiRunner.java:49)
	at org.jboss.weld.environment.se.Weld.initialize(Weld.java:777)
	at org.jglue.cdiunit.NgCdiRunner.initializeCdi(NgCdiRunner.java:64)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
	at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
	at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:340)
	at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:294)
	at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:683)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:510)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.testng.TestRunner.privateRun(TestRunner.java:770)
	at org.testng.TestRunner.run(TestRunner.java:591)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
	at org.testng.SuiteRunner.run(SuiteRunner.java:304)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)

Adding the JUnit 4 dependency makes the test pass. However, some other testing related frameworks might require an absence of JUnit for detecting a different like TestNG framework as the actually used testing framework.

The cause of this bug seems to be be caused by a "hard" reference on org.jglue.cdiunit.internal.WeldTestUrlDeployment in line 405 as org.jglue.cdiunit.internal.CdiRunner is derived from BlockJUnit4ClassRunner. This pull request contains a fix for it.

ikysil added a commit to ikysil/cdi-unit that referenced this pull request May 9, 2020
@ikysil
Copy link
Collaborator

ikysil commented May 9, 2020

Superseded by #173

@ikysil ikysil closed this May 9, 2020
@ikysil ikysil added this to the 4.2.0 milestone May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants