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

@QuarkusIntegrationTest fails after adding io.quarkus:quarkus-junit5-mockito #43796

Open
sku0x20 opened this issue Oct 10, 2024 · 6 comments
Open

Comments

@sku0x20
Copy link
Contributor

sku0x20 commented Oct 10, 2024

Describe the bug

  • after adding io.quarkus:quarkus-junit5-mockito as test dependency, @QuarkusIntegrationTest starts to fail.
  • both @QuarkusTest and @QuarkusIntegrationTest are in integrationTest source set.
  • tests are launched via gradlew quarkusIntTest
  • @QuarkusTest marked tests pass.
  • @QuarkusIntegrationTest fails even when @InjectMock is not used
  • @QuarkusIntegrationTest works as expected when io.quarkus:quarkus-junit5-mockito not added and using QuarkusMock.installMockForType in @QuarkusTest
  • happen when @QuarkusTest runs before @QuarkusIntegrationTest

Expected behavior

@QuarkusIntegrationTest should not be affected by io.quarkus:quarkus-junit5-mockito

Actual behavior

java.lang.NoSuchMethodException: io.quarkus.test.junit.mockito.internal.SetMockitoMockAsBeanMockCallback.beforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext)
        at java.base/java.lang.Class.getMethod(Class.java:2395)
        at io.quarkus.test.junit.AbstractTestWithCallbacksExtension.invokeCallbacks(AbstractTestWithCallbacksExtension.java:157)
        at io.quarkus.test.junit.AbstractTestWithCallbacksExtension.invokeBeforeEachCallbacks(AbstractTestWithCallbacksExtension.java:76)
        at io.quarkus.test.junit.AbstractTestWithCallbacksExtension.invokeBeforeEachCallbacks(AbstractTestWithCallbacksExtension.java:72)
        at io.quarkus.test.junit.QuarkusIntegrationTestExtension.beforeEach(QuarkusIntegrationTestExtension.java:121)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

How to Reproduce?

bug-report.zip

Output of uname -a or ver

Microsoft Windows [Version 10.0.22631.4169]

Output of java -version

java version "21.0.4" 2024-07-16 LTS Java(TM) SE Runtime Environment Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41) Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41, mixed mode, sharing)

Quarkus version or git rev

3.15.1

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

------------------------------------------------------------ Gradle 8.9 ------------------------------------------------------------ Build time: 2024-07-11 14:37:41 UTC Revision: d536ef36a19186ccc596d8817123e5445f30fef8 Kotlin: 1.9.23 Groovy: 3.0.21 Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023 Launcher JVM: 21.0.4 (Oracle Corporation 21.0.4+8-LTS-jvmci-23.1-b41) Daemon JVM: C:\Program Files\Java\graalvm-jdk-21.0.4+8.1 (no JDK specified, using current Java home) OS: Windows 11 10.0 amd64

Additional information

No response

@sku0x20 sku0x20 added the kind/bug Something isn't working label Oct 10, 2024
@quarkus-bot quarkus-bot bot added area/kotlin area/testing env/windows Impacts Windows machines labels Oct 10, 2024
Copy link

quarkus-bot bot commented Oct 10, 2024

/cc @geoand (kotlin,testing)

@sku0x20
Copy link
Contributor Author

sku0x20 commented Oct 10, 2024

quarkiverse/quarkus-mockk#178 in quarkus-mockk might be related to this

@sku0x20
Copy link
Contributor Author

sku0x20 commented Oct 10, 2024

trying to debug

  • related to quarkus junit extensions callback mechanism
  • even if i disable callbacks for integration-test with quarkus.test.enable-callbacks-for-integration-tests still same error as beforeEachCallbacks in io.quarkus.test.junit.AbstractTestWithCallbacksExtension is static and QuarkusIntegrationTestExtension also gets the callback
  • tests are not designed to be mixed but imo its a valid use case since from my applications perspective both @QuarkusTest and @QuarkusIntegrationTest are integration tests only.

@geoand
Copy link
Contributor

geoand commented Oct 14, 2024

As you've seen, @QuarkusTest and @QuarkusIntegrationTest are not meant to be fixed in the same run.

If you are willing to look into providing a way for a way to make that happen, I'll gladly review it, but we ourselves won't be spending time on this.

Thanks for your understanding.

@geoand geoand added kind/enhancement New feature or request and removed kind/bug Something isn't working env/windows Impacts Windows machines labels Oct 14, 2024
@sku0x20
Copy link
Contributor Author

sku0x20 commented Oct 14, 2024

no issues.
imo, its better to close these issues with this limitation being explicitly mentioned in docs and guided towards creating new custom sourcesets.

  • another caveat is build.output.directory; it could in these cases also be auto detected, but rn sourcesets are hardcoded.
  • as additional benefit custom intTest is not dependent on quarkusBuild and is significantly faster than quarkusIntTest
/** custom source sets
 *
 * io.quarkus.gradle.QuarkusPlugin
 * io.quarkus.test.junit.IntegrationTestUtil
 *
 * to work around
 *  https://github.com/quarkusio/quarkus/issues/43796
 *  https://github.com/quarkusio/quarkus/issues/43804
 */

sourceSets {
    create("intTest") {
        compileClasspath += sourceSets.main.get().output
        runtimeClasspath += sourceSets.main.get().output
    }
    create("e2eTest") {
        compileClasspath += sourceSets.main.get().output
        runtimeClasspath += sourceSets.main.get().output
    }
}

configurations {
    getByName("intTestImplementation") {
        extendsFrom(configurations.testImplementation.get())
    }
    getByName("intTestRuntimeOnly") {
        extendsFrom(configurations.testRuntimeOnly.get())
    }
    getByName("e2eTestImplementation") {
        extendsFrom(configurations.testImplementation.get())
    }
    getByName("e2eTestRuntimeOnly") {
        extendsFrom(configurations.testRuntimeOnly.get())
    }
}

tasks.register<Test>("intTest") {
    group = "verification"
    description = "Runs integration tests"

    testClassesDirs = sourceSets["intTest"].output.classesDirs
    classpath = sourceSets["intTest"].runtimeClasspath

    systemProperty("build.output.directory", "build")
    systemProperty("quarkus.profile", "intTest")
}

tasks.register<Test>("e2eTest") {
    group = "verification"
    description = "Runs e2e tests"

    val quarkusBuild = tasks.getByName("quarkusBuild")
    dependsOn(quarkusBuild)

    testClassesDirs = sourceSets["e2eTest"].output.classesDirs
    classpath = sourceSets["e2eTest"].runtimeClasspath

    systemProperty("build.output.directory", "build")
}

idea.module {
    testSources.from(sourceSets["intTest"].kotlin.srcDirs)
    testSources.from(sourceSets["e2eTest"].kotlin.srcDirs)
}

@geoand
Copy link
Contributor

geoand commented Oct 14, 2024

imo, its better to close these issues with this limitation being explicitly mentioned in docs and guided towards creating new custom sourcesets.

Would you like to contribute this docs update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants