Bug #9649
Plain JUnit5 tests cannot execute if p2j.jar is in classpath
100%
History
#1 Updated by Vladimir Tsichevski over 1 year ago
- Status changed from New to WIP
- File 9649.png added
If the launch configuration classpath includes a FWD project (namely the p2j.jar) explicitly or implicitly (through the Java extension mechanism),
then it is impossible to run any plain JUnit5 tests.
The problem origin:
- JUnit5 unconditionally discovers all test engines in the classpath using the "services" mechanism, so it always discovers the FWD test engine.
- JUnit5 fails to initialize the FWD test engine (it requires proper FWD client-server environment)
- JUnit5 aborts the process, so the ordinary JUnit5 tests (run by the JUnit5 Jupiter engine) are never executed.
Unfortunately, this may happen for any Java project. The most surprising situation is if the project is not related to FWD, but uses a JRE with p2j.jar installed into the JRE lib/ext directory :-(
Workarounds:
- Junit5 console launcher allows to explicitly exclude test engines, so the problem can be workarounded
- Eclipse test runner does not allow this, so for Eclipse there is no workarounds.
The proposed cure:
Currently the exceptions generated by FWD test engine generation, are not caught, and propagate to the JUnit5 launcher, causing it to abort:
switch (state)
{
case INITIALIZED:
break;
case NONE:
final ConfigurationParameters configurationParameters = discoveryRequest
.getConfigurationParameters();
if (initialize(
configurationParameters.get(CFG_FWD_CONFIG_FILE).orElse(DEFAULT_FWD_CONFIG_FILE)))
{
state = State.INITIALIZED;
break;
}
//$FALL-THROUGH$
case INOPERABLE:
return new NoopDescriptor(UniqueId.forEngine(getId()), "No-op");
}
the fix: intercept exceptions and switch the engine to inoperable state:
switch (state)
{
case INITIALIZED:
break;
case NONE:
final ConfigurationParameters configurationParameters = discoveryRequest
.getConfigurationParameters();
try
{
if (initialize(configurationParameters.get(CFG_FWD_CONFIG_FILE)
.orElse(DEFAULT_FWD_CONFIG_FILE)))
{
state = State.INITIALIZED;
break;
}
}
catch (@SuppressWarnings("unused") final Throwable t)
{
// no-op, continue as inoperable
}
state = State.INOPERABLE;
//$FALL-THROUGH$
case INOPERABLE:
return new NoopDescriptor(UniqueId.forEngine(getId()), "No-op");
}
this also cures another bug: currently the INOPERABLE state is never assigned.
After this done, the FWD test engine results still look like one failed test, but other test engines execute normally:
#2 Updated by Greg Shah over 1 year ago
- Project changed from Regression Testing to Build and Source Control
#3 Updated by Greg Shah over 1 year ago
- Status changed from WIP to Internal Test
The proposed change seems to be a resasonable improvement. Go ahead and put it in a branch and get it tested.
#4 Updated by Vladimir Tsichevski over 1 year ago
- % Done changed from 0 to 100
Greg Shah wrote:
The proposed change seems to be a resasonable improvement. Go ahead and put it in a branch and get it tested.
Branch 9649a, rev. 15703 has the fix.
#5 Updated by Greg Shah over 1 year ago
- Project changed from Build and Source Control to Testing
#6 Updated by Vladimir Tsichevski over 1 year ago
I've finished testing: with trunk, it is impossible to run JUnit5 tests in the test/ subdirectory.
With 9649a this is now possible.
The branch has just been rebased and is now ready to be merged.
#7 Updated by Greg Shah over 1 year ago
Have you tested ABLUnit tests in some non-trivial 4GL project?
#8 Updated by Vladimir Tsichevski over 1 year ago
Greg Shah wrote:
Have you tested ABLUnit tests in some non-trivial 4GL project?
Why?
This change addresses situations where the FWD test engine fails to start, preventing the discovery of any ABLUnit or OEUnit tests.
#9 Updated by Greg Shah over 1 year ago
I just don't want to commit to trunk and then find that we have caused a problem for existing ABLUnit users (e.g. not from Eclipse).
#10 Updated by Vladimir Tsichevski over 1 year ago
Greg Shah wrote:
I just don't want to commit to trunk and then find that we have caused a problem for existing ABLUnit users (e.g. not from Eclipse).
I attempted to run ABLUnit tests for our big customer application, however, I could not start the server. See #7143-1420.
#11 Updated by Vladimir Tsichevski over 1 year ago
I ran tests for our large customer’s application using trunk and 9649a, and the results were identical. I gather that the testing is complete.
#12 Updated by Greg Shah over 1 year ago
- Status changed from Internal Test to Merge Pending
Merge to trunk after 9498a.
#13 Updated by Vladimir Tsichevski over 1 year ago
Greg Shah wrote:
Merge to trunk after 9498a.
Merged as trunk rev. 15752.
#14 Updated by Greg Shah over 1 year ago
- Status changed from Merge Pending to Test
#15 Updated by Hynek Cihlar 5 months ago
Vladimir, when I run ./gradlew test in FWD project I get the following output. Should the "plain" tests just work?
> Task :test FAILED
Thanks for using JUnit! Support its development at https://junit.org/sponsoring
╷
├─ JUnit Platform Suite ✔
└─ No-op ✘ Test engine was not initialized.
Failures (1):
No-op
=> java.lang.Exception: Test engine was not initialized.
com.goldencode.p2j.testengine.NoopDescriptor.execute(NoopDescriptor.java:211)
com.goldencode.p2j.testengine.NoopDescriptor.execute(NoopDescriptor.java:79)
com.goldencode.p2j.testengine.FWDTestEngine$FWDThrowableCollector.execute(FWDTestEngine.java:412)
com.goldencode.p2j.testengine.FWDTestEngine$FWDThrowableCollector.execute(FWDTestEngine.java:412)
Test run finished after 11 ms
[ 1 containers found ]
[ 0 containers skipped ]
[ 1 containers started ]
[ 0 containers aborted ]
[ 1 containers successful ]
[ 0 containers failed ]
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 1 tests failed ]
WARNING: Delegated to the 'execute' command.
This behaviour has been deprecated and will be removed in a future release.
Please use the 'execute' command directly.
[Incubating] Problems report is available at: file:///home/hc/gcd/p2j_repo/review/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.