Currently I am trying to upgrade my Jakarta EE sample project to Jakarta EE 10, and the testing libs is upgrade to Arquillian 1.7.0.x and JUnit 5.
But there is an issue of method injection which works well with Arquillian 1.6.0/JUnit 4, but failed in the new stack.
The problem is JUnit 5 try to resolve the method parameter with its own ParameterResolver, what I need here the method parameter is injected by Arquillian like a CDI Injection.
There is a Method parameter injection discussion in the Arquillian Github issues.
The following is an Arquillian test example to inject an initial Page instance.
#Test
public void testHomePageObject(#InitialPage HomePage home) {
home.assertTodoTasksSize(2);
}
When running the tests, it will fail due to lack of related JUnit 5 Parameter resolver.
I also encountered similar issues when integrating Vertx and Weld/CDI, see https://github.com/hantsy/vertx-sandbox/tree/master/post-service-cdi
Is there an option to skip parameter resolving by JUnit 5?
Related
Me and my team just moved from JUnit4 to JUnit5 and we faced with parallelism issues. With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore. I set up (at least I think so) junit platform engine for the project (https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit-platform-engine#configuration-options), but when I try to run tests via comand line (using Gradle task), I receive following error:
UnknownClass.Cucumber > UnknownClass.initializationError FAILED
org.junit.platform.commons.JUnitException at EngineExecutionOrchestrator.java:114
Caused by: org.junit.platform.commons.JUnitException at HierarchicalTestEngine.java:57
Caused by: org.junit.platform.commons.JUnitException at DefaultParallelExecutionConfigurationStrategy.java:41
Unfortunately, didn't find something in the internet, maybe someone can help with it?
What we use:
Spring boot 2.7.3
Gradle 7.5.1
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
Tasks in build.gradle that I have now:
useJUnitPlatform()
systemProperty("cucumber.junit-platform.naming-strategy", "long")
systemProperty("cucumber.execution.parallel.enabled", true)
systemProperty("cucumber.execution.parallel.config.strategy", "fixed")
systemProperty("cucumber.plugin", "html:reports/html")
systemProperty("cucumber.plugin", "pretty")
systemProperty("cucumber.plugin", "junit:reports/junit")
doLast {
javaexec {
mainClass.set("io.cucumber.core.cli.Main")
classpath = cucumberRuntime + sourceSets.test.get().output + sourceSets.main.get().output
}
}
}
tasks {
val consoleLauncherTest by registering(JavaExec::class) {
dependsOn(testClasses)
val reportsDir = file("$buildDir/test-results")
outputs.dir(reportsDir)
classpath = sourceSets["test"].runtimeClasspath
mainClass.set("org.junit.platform.console.ConsoleLauncher")
args("--scan-classpath")
args("--include-engine", "cucumber")
args("--reports-dir", reportsDir)
}
test {
dependsOn(consoleLauncherTest)
exclude("**/*")
}
}
Configuration class:
#CucumberContextConfiguration
#Suite
#IncludeEngines("cucumber")
#SelectClasspathResource("com/example")
#ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
#SpringBootTest
#ContextConfiguration(classes = [IntegrationContext::class], loader = SpringBootContextLoader::class)
class Application() {}
Your question is pretty much impossible to answer because you didn't go through the process of making a minimal reproducer. For your next question please read the "Help others reproduce the problem" section in How do I ask a good question?.
With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore.
Project typically include a CHANGELOG and release notes documenting all relevant changes.
What we use:
Spring boot 2.7.3
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
These dependencies don't converge and aren't quite correct. You'll want to use Cucumber's and JUnit's Bill of Materials to avoid having to specify the version for every module.
If you're using Spring Boot in the recommended way you may also be able to omit the junit-bom altogether.
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation(platform("io.cucumber:cucumber-bom:7.9.0"))
testImplementation("io.cucumber:cucumber-java")
testImplementation("io.cucumber:cucumber-junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-suite")
testImplementation("org.junit.jupiter:junit-jupiter")
}
Tasks in build.gradle that I have now:
So in this build file it appears that you are trying to run Cucumber in 3 different ways. Through the JUnit Platform, through Cucumbers CLI and through the JUnit 5 ConsoleLauncher.
I don't know which solution you are trying use but suppose that you want to use the JUnit Platform, then you look at cucumber-java-skeleton for a working example.
Then afterwards you should clean up your build file. :D
I do the following:
From the Package Explorer I select "New, Other, JUnit Test Case"
I write this code:
package dk.sample;
import org.junit.*;
import static org.junit.Assert.*;
public class TestCase {
#Test
public void alwaysTrue(){
assertTrue( true );
}
}
I then select "Run As, JUnit test"
Get this error: "Class not found dk.sample.TestCase
java.lang.ClassNotFoundException: ...."
What do I miss? Have tried with different Run Configurations - but it seems like I miss a classpath somewhere? But to what and where?
To make JUnit work within Domino Designer you need to perform few additional steps:
set up source control for your application
adjust the on-disk project to be recognized as Java application
run JUnit tests within your on-disk project
Please note that java agents have to be tested in a different way..
You can find more detailed explanation about enabling JUnit for both XPages and Agents in the following blog post: Unit Tests for Lotus Domino Applications
Here's also a great how-to on this topic.
Coundn't get JUnit to work inside the Domino Designer. Instead of running the tests from DDE, I now run the tests from a XPages. This works like a dream. Made my own 'JUnit runner' class - that is, I just call the JUnit runners but handles the result my self in order to display it as html on the XPage.
Code can be found here: http://xpages.dk/wp-content/uploads/2013/10/junitrunner.txt
Danish blog post here: http://xpages.dk/?p=1162
I have not found any related searches to my problem here and hence Im writing this one.
I have a JUnit Class
MyHandler Class with tests - testx,testy,testz
that calls other JUnit Classes
MyTestA, MyTestB classes each having tests
based on some logic
MyTestA has tests - testa1, testa2, testa3
MyTestB has tests - testb1, testb2, testb3
Everything works fine, except that the report shows only 3 tests executed (testx,testy,testz) - Though all the tests in MyTestA, MyTestB are also executed, they are not part of the report.
I see this when using Junit reporting using ant and also in Eclipse IDE.
Within MyHandler Class, I am calling the JUnit classes as ,
org.junit.runner.JUnitCore.runClasses(MyTestA)
org.junit.runner.JUnitCore.runClasses(MyTestB)
Is there anyway, we can include the individual called junit tests in the Junit report?
We are using ant to build along with junit reporting.
Appreciate any help on this,
Sudhakar
JUnit will only report on the structure it knows about, so use a JUnit test suite (Junit4 Test Suites). You can list all the test classes and JUnit will run them and also include them in the report.
I'm trying to use EJB 3.1 Embeddable EJBContainer on Glassfish 3.1 for integration
testing my EJB's. There's a classloading issue I can't figure out.
My ejbs are build into dum-ejb.jar. They use EclipseLink JPA. I also create EJB client jar dum-ejb-client.jar, while attempting to fight the classloading issues. Client jar contains the EJB interfaces, and Entity classes (which are usually parameters or returns values). Client jar also contains a lot of unneeded classes that could be dropped (but I don't see how it would solve the problem).
The problem is that since EclipseLink does bytecode weaving to the Entity classes, the Entity classes must not be in the classpath when the junit tests are run: http://www.java.net/forum/topic/glassfish/glassfish/embedded-glassfish-and-weaving
I can do that and configure classpath so that dum-ejb.jar is not included. If I use EJBContainer so that I look up my service as a java.lang.Object and call it's methods via reflection, the test works. But of course, that's not how I want to write my tests.
Typical test would be like:
#Test
public void testInEJBContainer() throws Exception {
File ejbJarFile = new File("target/dum/dum-ejb.jar");
Map props = new HashMap();
props.put("org.glassfish.ejb.embedded.glassfish.instance.root",
"target/classes/instance-root");
props.put(EJBContainer.MODULES, new File[]{ejbJarFile});
EJBContainer container = EJBContainer.createEJBContainer(props);
CompanyService = (CompanyService)
container.getContext().lookup("java:global/dum/CompanyServiceImpl");
log.info("result of findAll() " + service.findAll(false));
}
How could I run the test if CompanyService interface, and returned Company Entity classes can not be in the classpath?
Even if dum-ejb.jar is not on classpath, and dum-ejb-client.jar is, EclipseLink weaving gets broken.
Isn't this exactly the typical use case for EJBContainer, shouldn't there be a simple solution to this?
Turns out I ran into classloading problems since I was running the EJBContainer from maven ear project.
When I run it from the maven ejb project itself, there's no such issues and EJBContainer is easy to use.
Hallo,
I have the following situation:
We are developing an Eclipse RCP Application and want to switch from Eclipse 3.4 to Eclipse 3.5. Our JUnit-Tests are using JUnit 4.3.1 and we have a launch configuration to start our test suite. I think I don't need to go into more details here.
The problem is:
Running the tests with Eclipse 3.5 does not work: JUnit cannot find any annotations in the test classes (neither (at)Test nor (at)RunWith).
I patched the junit library with some logging output to check what is going on. I found out that this problem is a classloading issue:
The test class passed to JUnit 'lies in' a ClassLoader which is different from the one JUnit uses to load the annotation classes like 'RunWith'. This is not the case in Eclipse 3.4
in org.junit.internal.requests.ClassRequest:
public Runner getRunner() {
log("TestClass ClassLoader: "+this.fTestClass.getClassLoader());
log("RunWith.class ClassLoader: "+RunWith.class.getClassLoader());
... // validating test class: searching for annotations and more
}
The first line prints another classloader than the second line. This is bad because JUnit cannot match the annotations in the test class with the Annotation-Class (here: RunWith.class): "RunWith" in CL1 is not equal to "RunWith" in CL2.
I have a solution which points to the core problem: Replace JUnit 4.5 in Eclipse Galileo with JUnit 4.3.1 so that there is only one JUnit-Version: The Test-Run and the tests classes are both using JUnit 4.3.1 (I had to patch "org.eclipse.jdt.junit4.runtime" to accept an ealier junit version).
I think I can also replace JUnit 4.3.1 in my test class with Version 4.5, but that is not an option yet.
Guess: The classloaders are different because the classes 'come from' different JUnit-Bundles: the testclass with its annotations from version 4.3.1 and the test runs in version 4.5
What I want to know: Is there any other solution besides patching Eclipse (replace JUnit versions)? Any commandline argument or such? Any configuration to force Eclipse to Use JUnit 4.3.1?
Any hints on the above described analysis are welcome!
I'm not sure that's what you're looking for but:
In the Run Configuration of your JUnit tests, you can choose the Test Runner you want to use (JUnit 4, JUnit 3...)