Open LayMui-Toh opened 4 years ago
I think you need to specify the local port the server is running on, either explicitly in a constructor or via env vars: https://github.com/DiUS/pact-jvm/blob/5d8bfd2d1f2220ac4a1fde90b7bab54d36d59874/provider/pact-jvm-provider-spring/src/main/kotlin/au/com/dius/pact/provider/spring/SpringInteractionRunner.kt#L103
This is a good article on testing a spring boot app if you haven't read it https://reflectoring.io/consumer-driven-contract-provider-pact-spring/
Try adding webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
to the @SpringBootTest
annotation
I get this error when running pact provider test
java.lang.NumberFormatException: null
Here is my pact file content: { "consumer": { "name": "Consumer" }, "provider": { "name": "Provider" }, "interactions": [ { "description": "accessToken", "providerState": "Authenticate with valid clientId", "request": { "method": "POST", "path": "/api/external/authenticate", "headers": { "Accept": "/", "Content-Type": "application/json" }, "body": { "clientId": "admin", "clientSecret": "admin" }, "matchingRules": { "$.body": { "match": "type" } } }, "response": { "status": 200, "headers": { "Content-Type": "application/json;charset=UTF-8" }, "body": { "accessToken": "dfasdfjdsakfjsdfjsadjfsdl", "timeLeftRefreshThresholdMs": 1800000, "authenticationErrorMsg": "null" }, "matchingRules": { "$.body": { "match": "type" } } }, "metadata": null } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }
here is my provider code snippet: package com.taiger.iconverse.admin.web.pact;
import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.State; import au.com.dius.pact.provider.junit.loader.PactFolder; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; import au.com.dius.pact.provider.spring.SpringRestPactRunner; import au.com.dius.pact.provider.spring.target.SpringBootHttpTarget; import com.taiger.admin.AdminApp; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource;
@RunWith(SpringRestPactRunner.class) @Provider("Provider") @PactFolder("src/test/resources/pacts") @SpringBootTest(classes = AdminApp.class) public class AuthenticatePactTest { @TestTarget public final Target target = new SpringBootHttpTarget();
}