zerocode
zerocode copied to clipboard
JUnit5 compatibility with other extensions
I'm running a server based on the Vert.x framework. To support testing of asynchronous code, they provide a JUnit5 extension which injects an instance of Vertx and a VertxTestContext. In order for a test to complete, one has to call complete() or fail(Throwable) on the test context or use one of the helper methods that invoke them.
@Test
fun testSomeRequest(vertx: Vertx, testContext: VertxTestContext) {
invokeSomeCodeThatReturnsFuture().onComplete(testContext.completing())
}
When trying to compose a test like this with into Zerocode test using a TestMapping annotation, it will fail to identify this as a test method because it only looks for argument-less test methods (i.e. methodParameterTypes = '').
Caused by: org.junit.platform.commons.JUnitException: MethodSelector [className = 'my.TestClass', methodName = 'testSomeRequest', methodParameterTypes = ''] resolution failed
at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:102)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:82)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:45)
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:181)
Is there a way to do this?
@milgner , we will have a look soon. The error seems to be JUnit5 Jupiter engine is unable to match the method or matching the method by '' no params, hence unable to find and execute the actual method.
I am assuming you are running the tests via @ExtendWith(VertxExtension.class) ?
@authorjapps thank you for the quick reply!
Yes, indeed. The tests run fine by themselves but in the context of @TestMapping they are not considered for execution anymore.
@authorjapps Any workaround for this ?