Open bwgjoseph opened 2 years ago
You are using a JUnit test, so you don't need the Pact Gradle plugin command, the normal Gradle test will do.
The problem is that Gradle will run your tests in a separate JVM process, so the properties from the command line won't be applied. See https://stackoverflow.com/questions/21406265/how-to-give-system-property-to-my-test-via-gradle-and-d how to set the properties correctly for the test.
Hey @rholshausen, thanks for getting back.
You are using a JUnit test, so you don't need the Pact Gradle plugin command, the normal Gradle test will do.
If I get you correctly, you meant that as long as I ran ./gradlew test
, it should automatically upload the verification to pact server
?
I tried a couple of ways, but still unable to get it uploaded.
System.setProperty
manually under test
tasktasks.named('test') {
useJUnitPlatform()
System.setProperty("pact.verifier.publishResults", "true");
}
And I ran ./gradlew clean test
. But nothing gets uploaded, although the report are generated.
tasks.named('test') {
useJUnitPlatform()
systemProperty "pact.verifier.publishResults", project.getProperty("pact.verifier.publishResults")
}
And I ran ./gradlew clean test -Ppact.verifier.publishResults=true
, I only face with this error
* What went wrong:
Your project is misconfigured, was expecting a 'pact' configuration in the build, but got a String with value '' instead. Make sure there is no property that is overriding 'pact'
Also tried ./gradlew pactVerify
which ran successfully but nothing happens. Then I tried ./gradlew pactVerify -Ppact.verifier.publishResults=true
which faced the same error of was expecting a 'pact' configuration in the build...
Not exactly sure where was configured wrongly, do enlighten. Thank you
Your project is misconfigured, was expecting a 'pact' configuration in the build
Option 2 is the correct way, don't know why you are getting that error. Try removing the Pact Gradle plugin (you don't need it), or just add an empty pact
block.
I made a newbie mistake earlier, and was running the command from the consumer
project.
Now that I have switched to the right project, and here's what I tried
./gradlew clean test -Ppact.verifier.publishResults=true
but encounter* What went wrong:
Task '.verifier.publishResults=true' not found in root project 'pact-provider'
Somehow, pact
was stripped off. Wondering if it's a terminal issue, so I switched to use standard command prompt
instead of powershell
, and this time it works. Any idea?
Also wondering, when would I need to use gradle plugin
then if that is not required?
Ah, looks like a Gradle doesn't like you using pact
in the property name.
BTW, the command line value doesn't have to be the same. Try
tasks.named('test') {
useJUnitPlatform()
systemProperty "pact.verifier.publishResults", project.publishResults
}
and then run ./gradlew clean test -PpublishResults=true
Even better, something like
tasks.named('test') {
useJUnitPlatform()
if (project.hasProperty("publishResults")) {
systemProperty "pact.verifier.publishResults", project.publishResults
}
}
Here is an example you can look at https://github.com/pactflow/example-provider-springboot
Thanks! That works if I rely on junit
, what if I wanted to use gradle plugin
as my original intention via pactVerify
? Where if I have it configured as such
tasks.named('test') {
useJUnitPlatform()
// nothing set here
}
pact {
broker {
pactBrokerUrl = 'http://localhost:9292'
pactBrokerUsername = 'pact'
pactBrokerPassword = 'pact'
}
serviceProviders {
ProfileProvider {
fromPactBroker {
selectors = latestTags('main')
}
providerTags = [project.pactBrokerTag]
}
}
reports {
defaultReports() // adds the standard console output
}
}
And I run gradlew pactVerify -Ppact.verifier.publishResults=true
in command prompt
, powershell
still hates -Ppact
for some reason.
And I still encounter this error
Verifying a pact between ProfileConsumer (0.0.1-SNAPSHOT) and ProfileProvider
Notices:
1) The pact at http://localhost:9292/pacts/provider/ProfileProvider/consumer/ProfileConsumer/pact-version/28b2b6450b198331505dab7cbd7fd53d0b867961 is being verified because the pact content belongs to the consumer version matching the following criterion:
* latest version tagged 'main' (0.0.1-SNAPSHOT)
[from Pact Broker http://localhost:9292/pacts/provider/ProfileProvider/consumer/ProfileConsumer/pact-version/28b2b6450b198331505dab7cbd7fd53d0b867961/metadata/c1tdW3RdPW1haW4mc1tdW2xdPXRydWUmc1tdW2N2XT05]
Given profiles 1 exists
WARNING: State Change ignored as there is no stateChange URL
get profile with id 1
Request Failed - Connect to http://localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: no further information
Given profiles exists
WARNING: State Change ignored as there is no stateChange URL
get all profiles
Request Failed - Connect to http://localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: no further information
Failures:
1) Verifying a pact between Pact between ProfileConsumer (0.0.1-SNAPSHOT) and ProfileProvider - get profile with id 1 Given profiles 1 exists
1.1) Connect to http://localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: no further information
1.2) Connect to http://localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: no further information
FAILURE: Build failed with an exception.
* What went wrong:
There were 2 non-pending pact failures for provider ProfileProvider
What is causing this to fail?
Here is an example you can look at https://github.com/pactflow/example-provider-springboot
I've seen that example before, but it also brings in gradle plugin
but not using it since it declares systemProperty
under test
task as well. So I'm not entirely sure the difference between using and not using the gradle plugin
The Pact Gradle plugin provides the pactVerify
task, you only need it if you want to run that. But there is no harm in having it in your project.
I don't know much about Powershell, I've never used it.
If you want to use gradlew pactVerify
, you need to have your provider running before. See https://github.com/pact-foundation/pact-jvm/tree/master/provider/gradle#starting-and-shutting-down-your-provider
It states that Gradle plugin for verifying pacts against a provider
but I'm actually trying to use my provider
to verify against the consumer
contracts. I'm actually trying to do this - https://github.com/pact-foundation/pact-jvm/tree/master/provider/gradle#verifying-pact-files-from-a-pact-broker
Why would I need to start up or shut-down the provider? I'm already running as the provider?
@rholshausen I have the similar issue with Maven. I want to use the plugin for 'verify_changed_pacts' workflow.
We are planning to have to 2 work flows for the provider (similar to https://github.com/pactflow/example-provider-springboot)
mvn clean test
- executes all unit tests (This will also run the provider contract tests)mvn pact:verify -Dpact.filter.consumers=foo -Dpact.filter.pacturl=bar
- execute only those tests that impacted by changed pact specified in the webhookAs per your suggestion, we don't need to use plugin we can run mvn clean test -Dpact.filter.consumers-foo -Dpact.filter.pacturl=bar
correct? But this will run all the unit tests rit ? not just tests related to changed pact specified in the webhook. Please correct me if i'm wrong.
I can further refine the mvn clean test
command to look into the contract test folder in the src but it will still run all the contract tests in the folder rit not just tests related to changed pact?
Hi,
I am trying out
Pact
as an exploration project, and right now, I am facing issue to publish the verification result to thebroker
usinggradle plugin
. You can refer to my demo repo for my setup.Disclaimer: I am still trying to learn
Pact
so I might be wrong in certain understanding, so please forgive me if I explain it wrongly.In summary
Spring Boot
docker
pactPublish
My only problem is that I can't publish the result to the broker via
./gradlew pactVerify
commandMy provider setup is as such
My application properties
When running the test (
./gradlew -i clean test
)This is the logs (partial)
For some reason, it states
Skipping publishing of verification results as it has been disabled
but I have it configured topact.verifier.publishResults=true
ingradle.properties
Well, I tried to pass the properties via gradle but encounter errors
I checked, and the closest seem to be this issue 738 but even after setting the
protocol, project.version
, it still doesn't work outBut if I were to run the following command
The test would fail with the following output
However, the failure result would still be published to the broker with the error like such
I did come across this question in SO and have tried to configure via
system property
but it doesn't work out as expected as well.I'm not quite sure what is causing the issue, do let me know if there's something I did wrong, or if I need to provide more information.
Thanks!