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

When using @QuarkusMainTest and @Launch, junit @BeforeEach is executed after launching the app #26711

Closed
benoit-messager opened this issue Jul 13, 2022 · 0 comments · Fixed by #26727
Assignees
Labels
area/testing kind/bug Something isn't working
Milestone

Comments

@benoit-messager
Copy link

benoit-messager commented Jul 13, 2022

Describe the bug

To test a command mode app i have a test class annotated with @QuarkusMainTest and a test resource that fires up a dynamodb container.
I want to run some logic before launching the batch, but if i annotate a method with junit@BeforeEach it is run after the app has already been launched by @Launch.
I also tried with a manual invocation with QuarkusMainLauncher but this time the dynamodb test resource isn't started.

Expected behavior

In a test class annotated with @QuarkusMainTest and a test method annotated with @Launch and @Test, a method annotated with @BeforeEach is run before the app is actually launched.

Also, when using standard @Test methods (not annotated with @Launch) and QuarkusMainLauncher test resources are executed.

Actual behavior

In a test class annotated with @QuarkusMainTest and a test method annotated with @Launch and @Test, a method annotated with @BeforeEach is run after the app is actually launched.

Also, when using standard @Test methods (not annotated with @Launch) and QuarkusMainLauncher test resources are not executed.

How to Reproduce?

Create a test with the scenario describe above, here's my test class simplified a bit :

@QuarkusMainTest
@TestProfile(DynamoDbDockerProfile::class)
class RetryCardCreationRequestBatchTest {

    lateinit var dynamodbContainerAddress: String

    private val dynamoDbCreationOrdersRepository: DynamoDbCreationOrdersRepository by lazy {
        DynamoDbCreationOrdersRepository(DynamoDbHelper.createDynamoClient(dynamodbContainerAddress))
    }

    lateinit var creationOrder: CreationOrder

    @BeforeEach
    fun setUp() {
        creationOrder = CreateOrderHelper.createOrder()
        dynamoDbCreationOrdersRepository.save(creationOrder,  Instant.now().minus(20, ChronoUnit.MINUTES),
            Instant.now().plus(20, ChronoUnit.DAYS))
    }

    @Test
    @Launch(value = [])
    fun `should resend card creation request`(result: LaunchResult?) {
        val creationOrder =
            dynamoDbCreationOrdersRepository.findByChannelAndOrderId(creationOrder.channel, creationOrder.orderId)
        creationOrder!!.status shouldBe CreationOrderStatus.SEND_TO_PARTNER
    }

    @AfterEach
    fun cleanUp() {
        dynamoDbCreationOrdersRepository.delete(creationOrder.channel, creationOrder.orderId)
    }
}

Output of uname -a or ver

Darwin LM-C02ZC045L415 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment Corretto-17.0.1.12.1 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.1.12.1 (build 17.0.1+12-LTS, mixed mode, sharing)

GraalVM version (if different from Java)

22.1.0

Quarkus version or git rev

2.9.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)

Additional information

No response

@benoit-messager benoit-messager added the kind/bug Something isn't working label Jul 13, 2022
geoand added a commit to geoand/quarkus that referenced this issue Jul 14, 2022
geoand added a commit to geoand/quarkus that referenced this issue Jul 14, 2022
The way this is done is pretty much a hack,
but we either have to do it this way, or
document that the combination of the two
does not work as expected

Fixes: quarkusio#26711
@geoand geoand self-assigned this Jul 14, 2022
geoand added a commit to geoand/quarkus that referenced this issue Jul 15, 2022
The way this is done is pretty much a hack,
but we either have to do it this way, or
document that the combination of the two
does not work as expected

Fixes: quarkusio#26711
geoand added a commit to geoand/quarkus that referenced this issue Sep 8, 2022
The way this is done is pretty much a hack,
but we either have to do it this way, or
document that the combination of the two
does not work as expected

Fixes: quarkusio#26711
geoand added a commit that referenced this issue Sep 8, 2022
@quarkus-bot quarkus-bot bot added this to the 2.13 - main milestone Sep 8, 2022
evanchooly pushed a commit to nenros/quarkus that referenced this issue Sep 8, 2022
The way this is done is pretty much a hack,
but we either have to do it this way, or
document that the combination of the two
does not work as expected

Fixes: quarkusio#26711
@gsmet gsmet modified the milestones: 2.13 - main, 2.12.2.Final Sep 12, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Sep 12, 2022
The way this is done is pretty much a hack,
but we either have to do it this way, or
document that the combination of the two
does not work as expected

Fixes: quarkusio#26711
(cherry picked from commit 9be7834)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants