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

Support using other JUnit @Disabled.. annotations #1844

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edeandrea
Copy link

Support for more than just JUnit's @Disabled annotation...

org.junit.jupiter.api.condition.DisabledForJreRange
org.junit.jupiter.api.condition.DisabledIf
org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
org.junit.jupiter.api.condition.DisabledIfEnvironmentVariables
org.junit.jupiter.api.condition.DisabledIfSystemProperties
org.junit.jupiter.api.condition.DisabledIfSystemProperty
org.junit.jupiter.api.condition.DisabledInNativeImage
org.junit.jupiter.api.condition.DisabledOnJre
org.junit.jupiter.api.condition.DisabledOnOs

@edeandrea
Copy link
Author

edeandrea commented Dec 9, 2024

I tried to run ./gradlew --no-daemon -p consumer check locally with Java 17 but couldn't get it to build (even before my change...)

╰─ ./gradlew --no-daemon -p core clean check && ./gradlew --no-daemon -p consumer clean check       
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.6.3/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build 

> Task :consumer:compileKotlin FAILED
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:13:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:14:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:15:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:16:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:17:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:18:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:19:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:20:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:21:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:22:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:23:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:24:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:25:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:26:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:27:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:28:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:29:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:30:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:31:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:32:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:34:8 Unresolved reference: kotlinx
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:35:8 Unresolved reference: kotlinx
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:47:21 Unresolved reference: applicationEngineEnvironment
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:49:7 Unresolved reference: sslConnector
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:52:9 Unresolved reference: host
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:53:9 Unresolved reference: port
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:56:7 Unresolved reference: connector
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:57:9 Unresolved reference: host
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:58:9 Unresolved reference: port
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:62:5 Unresolved reference: module
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:63:7 Unresolved reference: install
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:63:15 Unresolved reference: CallLogging
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:64:7 Unresolved reference: intercept
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:64:17 Unresolved reference: ApplicationCallPipeline
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:65:13 Unresolved reference: context
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:65:43 Unresolved reference: HttpMethod
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:65:65 Unresolved reference: context
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:66:11 Unresolved reference: context
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:67:11 Unresolved reference: context
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:67:27 Unresolved reference: HttpStatusCode
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:70:27 Suspend function 'toPactRequest' should be called only from a coroutine or another suspend function
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:70:41 Unresolved reference: context
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:74:13 Suspend function 'pactResponseToKTorResponse' should be called only from a coroutine or another suspend function
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:74:50 Unresolved reference: context
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:77:13 Suspend function 'pactResponseToKTorResponse' should be called only from a coroutine or another suspend function
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:78:96 Unresolved reference: context
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:85:23 Unresolved reference: NettyApplicationEngine
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:85:48 Unresolved reference: embeddedServer
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:85:63 Unresolved reference: Netty
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:87:77 Unresolved reference: ApplicationCall
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:96:34 Unresolved reference: HttpStatusCode
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:98:20 Unresolved reference: HttpStatusCode
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:102:43 Unresolved reference: ApplicationCall
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:105:24 Unresolved reference: withContext
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:105:36 Unresolved reference: Dispatchers
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:116:20 Overload resolution ambiguity: 
public final fun body(body: ByteArray?, contentType: ContentType): OptionalBody defined in au.com.dius.pact.core.model.OptionalBody.Companion
public final fun body(body: String?, contentType: ContentType = ...): OptionalBody defined in au.com.dius.pact.core.model.OptionalBody.Companion
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:119:53 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:120:37 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:127:30 Unresolved reference: hostname
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:130:17 Unresolved reference: hostname
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:132:43 Unresolved reference: port
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:141:11 Variable expected
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt:146:45 Unresolved reference: port
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt:28:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:10:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:11:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:49:9 Unresolved reference: parseHeaderValue
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:49:65 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:71:7 Unresolved reference: parseHeaderValue
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:71:52 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:78:9 Unresolved reference: parseHeaderValue
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:78:58 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:115:9 Unresolved reference: parseHeaderValue
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:115:72 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:169:9 Unresolved reference: parseHeaderValue
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:169:71 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:306:43 Unresolved reference: HeaderValue
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:308:62 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/HttpPartBuilder.kt:308:73 Unresolved reference: it
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockHttpsProviderConfig.kt:68:25 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockProviderConfig.kt:7:11 Unresolved reference: ktor
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockProviderConfig.kt:61:28 Unresolved reference: hostname
e: file:///Users/edeandre/workspaces/IntelliJ/pact-jvm/consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockProviderConfig.kt:64:15 Unresolved reference: hostname

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':consumer:compileKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
32 actionable tasks: 1 executed, 31 up-to-date

@rholshausen
Copy link
Contributor

This will only disregard the method if the annotation is present, but will not validate the condition.

I.e., in the test, changing

boolean shouldBeDisabled() {
    false
}

will still consider it disabled.

@edeandrea
Copy link
Author

Ooooh you are very right! I totally overlooked that! I'll take a look in the morning and see how to run the validation.

I'm not too familiar with JUnit's API, so if you have any hints or pointers I'm open :)

@rholshausen
Copy link
Contributor

I don't know it that well either. I'm also looking at the JUnit 5 API to see if there is a way to use them correctly.

@edeandrea
Copy link
Author

The use case I'm trying to solve is if I have an @Test method that has one of those annotations on it, the consumer test fails because at that point, not all of the @Pact methods had been executed. Is there a way to ignore (or conditionally ignore) an @Pact method?

@rholshausen
Copy link
Contributor

I understand the need for this. Unfortunately, there is nothing in the Jupiter APIs to work with those annotations. I found where they are invoked, but it is in the Jupiter engine and not usable from the Pact extension.

So there are two ways to achieve this:

  1. Implement support for those annotations. It is not too difficult, but is a bit involved. Each annotation has a condition class associated with it (for example, see https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/condition/DisabledIf.html). If you can get the annotation, you need to then lookup the condition class, and then invoke it's evaluateExecutionCondition method.

  2. As to your question, I don't know. Ideally, the pact method should be ignored if the associated test method is disabled. This is also a bit involved. It will need a way to determine if the pact method is associated with any test methods, and then if any of those test methods have been disabled. I don't know if there is a way to check if a test method was disabled (the test method will not be invoked, so there is no test context for it). Most of the API works with the test context.

@rholshausen
Copy link
Contributor

Looks like the only way I can find to determine if a test was disabled would be to implement TestWatcher and record any disabled test.

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

Successfully merging this pull request may close these issues.

2 participants