Skip to content

Commit

Permalink
QuarkusComponentTest: support repeated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed Feb 21, 2024
1 parent 54a9ea3 commit b7a6b48
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.jboss.jandex.Type;
import org.jboss.jandex.Type.Kind;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.RepetitionInfo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
Expand Down Expand Up @@ -1031,7 +1032,9 @@ private List<Parameter> findInjectMockParams(Class<?> testClass) {
}

static boolean isTestMethod(Executable method) {
return method.isAnnotationPresent(Test.class) || method.isAnnotationPresent(ParameterizedTest.class);
return method.isAnnotationPresent(Test.class)
|| method.isAnnotationPresent(ParameterizedTest.class)
|| method.isAnnotationPresent(RepeatedTest.class);
}

private List<Field> findFields(Class<?> testClass, List<Class<? extends Annotation>> annotations) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.quarkus.test.component.paraminject;

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

import java.util.concurrent.atomic.AtomicInteger;

import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.Dependent;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.RepetitionInfo;

import io.quarkus.test.component.QuarkusComponentTest;

@QuarkusComponentTest
public class ParameterInjectionRepeatedTest {
@RepeatedTest(10)
public void testParamsInjection(
// component under test
Converter converter,
// ignored automatically, no need for `@SkipInject`
RepetitionInfo info) {
assertEquals(10, info.getTotalRepetitions());
assertEquals("FOOBAR", converter.convert("fooBar"));
}

@AfterAll
public static void afterAll() {
assertEquals(10, Converter.DESTROYED.get());
}

@Dependent
public static class Converter {
static final AtomicInteger DESTROYED = new AtomicInteger();

String convert(String param) {
return param.toUpperCase();
}

@PreDestroy
void destroy() {
DESTROYED.incrementAndGet();
}
}
}

0 comments on commit b7a6b48

Please sign in to comment.