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

Ensure that @QuarkusTest plays nicely with @testfactory #8066

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
<parentFirstArtifact>org.objenesis:objenesis</parentFirstArtifact>
<parentFirstArtifact>net.bytebuddy:byte-buddy</parentFirstArtifact>
<parentFirstArtifact>net.bytebuddy:byte-buddy-agent</parentFirstArtifact>
<parentFirstArtifact>org.junit.jupiter:junit-jupiter-api</parentFirstArtifact>
<parentFirstArtifact>org.junit.jupiter:junit-jupiter-engine</parentFirstArtifact>
<parentFirstArtifact>org.junit.jupiter:junit-jupiter-params</parentFirstArtifact>
<parentFirstArtifact>org.junit.platform:junit-platform-commons</parentFirstArtifact>
<parentFirstArtifact>org.junit.platform:junit-platform-engine</parentFirstArtifact>
</parentFirstArtifacts>
<excludedArtifacts>
<excludedArtifact>io.smallrye:smallrye-config</excludedArtifact>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.it.main;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

import io.quarkus.it.arc.UnusedBean;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class DynamicTestsTestCase {

@Inject
UnusedBean bean;

@Test
public void testInjection() {
assertNotNull(bean);
}

@TestFactory
public List<?> dynamicTests() {
return Arrays.asList(
DynamicTest.dynamicTest("test 1", () -> {
assertNotNull(bean);
}),
DynamicTest.dynamicTest("test 2", () -> {
assertEquals(1, 1);
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,17 @@ public void interceptTestTemplateMethod(Invocation<Void> invocation, ReflectiveI
invocation.skip();
}

@Override
public <T> T interceptTestFactoryMethod(Invocation<T> invocation,
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
if (isNativeTest(extensionContext)) {
return invocation.proceed();
}
T result = (T) runExtensionMethod(invocationContext, extensionContext);
invocation.skip();
return result;
}

@Override
public void interceptAfterEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
Expand All @@ -342,7 +353,7 @@ public void interceptAfterAllMethod(Invocation<Void> invocation, ReflectiveInvoc
invocation.skip();
}

private void runExtensionMethod(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
private Object runExtensionMethod(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
throws Throwable {
Method newMethod = null;

Expand Down Expand Up @@ -389,7 +400,7 @@ private void runExtensionMethod(ReflectiveInvocationContext<Method> invocationCo
}
}

newMethod.invoke(actualTestInstance, argumentsFromTccl.toArray(new Object[0]));
return newMethod.invoke(actualTestInstance, argumentsFromTccl.toArray(new Object[0]));
} catch (InvocationTargetException e) {
throw e.getCause();
} catch (IllegalAccessException | ClassNotFoundException e) {
Expand Down