-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
@PactBroker not reading Spring properties with JUnit 5 #1023
Comments
I am also having the same issue. Waiting for the answer |
I've created a new module pact-jvm-provider-junit5-spring with a TestTemplateInvocationContextProvider that extends the current JUnit 5 one (PactVerificationSpringProvider). This should allow you to configure all the properties in the Spring context. |
That’s awesome! Thank you for such a quick response to the issue. This will make the developer experience smoother when running tests out of the box, with the broker having a default configuration in the properties file. |
HI @uglyog , I noticed a small inconsistency in the implementation of the SpringEnvironmentResolver.kt The |
@vtapadia I've removed the SystemPropertyResolver fallback |
@vtapadia removing the fallback breaks the pact loader, so I'm reverting the change |
Tested this with version 4.0.7 and replaced the However, I'm still getting this:
The stack trace suggests that it's still using the Am I missing something here? |
I did some debugging with this, and it seems that while the original commit to implement this worked, the change on line 395 of It seems that calling In override fun description(): String {
val resolver = setupValueResolver()
// ...
}
private fun setupValueResolver(): ValueResolver {
var valueResolver: ValueResolver = SystemPropertyResolver()
// ...
return valueResolver
} |
fix: @PactBroker not reading Spring properties with JUnit 5 #1023
4.0.8 released with this change |
I'm using this dependency
My code: @PactBroker(scheme = "https", host = "${pactbroker.host}", authentication = @PactBrokerAuth(token = "${pactbroker.auth.token}")) public class PriceServicePactTests {
and facing the same problem: java.lang.RuntimeException: Could not resolve property "pactbroker.host" in the system properties or environment variables and no default value is supplied any help would be appreciated. Thanks in advance. |
@gustavotpd |
Hi, I want to disable pact tests in local build . With regards to same I am using Could not resolve property "${pact.verification.ignoreIoErrors}" in the system properties or environment variables and no default I am using pact plugin Can you pls help? |
@vijays2017 the property needs to be set on the test JVM. See https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html on how to do this with the Maven Surfire plugin, which is what runs the tests with Maven. |
@uglyog I ended up with this code to make it work
|
@bijancn Can you expand on what you mean by "should really be mentioned in the docs". It is documented here: https://github.com/pact-foundation/pact-jvm/tree/master/provider/junit5spring#usage |
Sure, sorry. In the documentation, it says
So, the
|
@bijancn I just verified with my test project: https://github.com/uglyog/springboot-junit5-test That project works loading the broker properties from |
Could it be a Java vs Kotlin thing? It definitely doesn't work for me. But maybe you can also link to your example project? I wasn't aware of that and it would have helped me. |
@bijancn I was able to use
Here's my code snippet
|
The issue is that the |
That is standard Spring behavior. Pact-JVM is not Spring specific. |
If you provide system properties in Spring
application.yml
these won't be read by the@PactBroker
annotation when running with JUnit 5. This works fine if you provide them as normal system properties.This issue seems to have been fixed for the JUnit 4 runners in here: #632
I can see that the problem has been fixed by adding a property resolver, and that it is also possible to pass a
valueResolver
attribute for the@PactBroker
annotation. However, since you need a Spring context to be able to create such a resolver for Spring, it cannot be done with the annotation.I also tried to add a resolver into
PactVerificationContext
in@BeforeEach
but that didn't seem to do the trick.The text was updated successfully, but these errors were encountered: