MVN

au.com.dius.pact.provider : junit5spring

Maven & Gradle

Nov 25, 2022

junit5spring · # Pact Spring/JUnit5 Support This module extends the base [Pact JUnit5 module](/provider/junit5/README.md). See that for more details. ## Dependency The combined library (JUnit5 + Spring) is available on maven central using: group-id = au.com.dius.pact.provider artifact-id = junit5spring version-id = 4.1.x ## Usage For writing Spring Pact verification tests with JUnit 5, there is an JUnit 5 Invocation Context Provider that you can use with the `@TestTemplate` annotation. This will generate a test for each interaction found for the pact files for the provider. To use it, add the `@Provider` and `@ExtendWith(SpringExtension.class)` and one of the pact source annotations to your test class (as per a JUnit 5 test), then add a method annotated with `@TestTemplate` and `@ExtendWith(PactVerificationSpringProvider.class)` that takes a `PactVerificationContext` parameter. You will need to call `verifyInteraction()` on the context parameter in your test template method. For example: ```java @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @Provider("Animal Profile Service") @PactBroker public class ContractVerificationTest { @TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } } ``` You will now be able to setup all the required properties using the Spring context, e.g. creating an application YAML file in the test resources: ```yaml pactbroker: host: your.broker.host auth: username: broker-user password: broker.password ``` You can also run pact tests against `MockMvc` without need to spin up the whole application context which takes time and often requires more additional setup (e.g. database). In order to run lightweight tests just use `@WebMvcTest` from Spring and `MockMvcTestTarget` as a test target before each test. For example: ```java @WebMvcTest @Provider("myAwesomeService") @PactBroker class ContractVerificationTest { @Autowired private MockMvc mockMvc; @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) { context.setTarget(new MockMvcTestTarget(mockMvc)); } } ``` You can also use `MockMvcTestTarget` for tests without spring context by providing the controllers manually. For example: ```java @Provider("myAwesomeService") @PactFolder("pacts") class MockMvcTestTargetStandaloneMockMvcTestJava { @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) { MockMvcTestTarget testTarget = new MockMvcTestTarget(); testTarget.setControllers(new DataResource()); context.setTarget(testTarget); } @RestController static class DataResource { @GetMapping("/data") @ResponseStatus(HttpStatus.NO_CONTENT) void getData(@RequestParam("ticketId") String ticketId) { } } } ``` **Important:** Since `@WebMvcTest` starts only Spring MVC components you can't use `PactVerificationSpringProvider` and need to fallback to `PactVerificationInvocationContextProvider` ## Modifying requests As documented in [Pact JUnit5 module](/provider/junit5/README.md#modifying-the-requests-before-they-are-sent), you can inject a request object to modifiy the requests made. However, depending on the Pact test target you are using, you need to use a different class. | Test Target | Class to use | |-------------|--------------| | HttpTarget, HttpsTarget, SpringBootHttpTarget | org.apache.http.HttpRequest | | MockMvcTestTarget | MockHttpServletRequestBuilder | # Test Analytics We are tracking anonymous analytics to gather important usage statistics like JVM version and operating system. To disable tracking, set the 'pact_do_not_track' system property or environment variable to 'true'.

<dependency>
    <groupId>au.com.dius.pact.provider</groupId>
    <artifactId>junit5spring</artifactId>
    <version>4.1.40</version>
</dependency>
Copy
pom.xml
Table Of Contents

Latest Version

Choose a version of au.com.dius.pact.provider : junit5spring to add to Maven or Gradle - Latest Versions:

  • Latest Stable: 4.1.40
  • Latest Beta: 4.4.0-beta.8

All Versions

Choose a version of au.com.dius.pact.provider : junit5spring to add to Maven or Gradle - All Versions:

  • Version Updated
  • junit5spring-4.1.40

    Nov 25, 2022
  • junit5spring-4.4.2

    Nov 22, 2022
  • junit5spring-4.4.1

    Nov 21, 2022
  • junit5spring-4.4.0

    Nov 18, 2022
  • junit5spring-4.4.0-beta.8

    Nov 16, 2022
  • junit5spring-4.3.17

    Nov 14, 2022
  • junit5spring-4.3.16

    Oct 28, 2022
  • junit5spring-4.4.0-beta.7

    Oct 11, 2022
  • junit5spring-4.4.0-beta.6

    Oct 11, 2022
  • junit5spring-4.3.15

    Sep 30, 2022
  • junit5spring-4.4.0-beta.5

    Sep 07, 2022
  • junit5spring-4.4.0-beta.4

    Aug 15, 2022
  • junit5spring-4.3.14

    Aug 12, 2022
  • junit5spring-4.1.39

    Aug 02, 2022
  • junit5spring-4.3.13

    Jul 31, 2022
  • junit5spring-4.4.0-beta.3

    Jul 27, 2022
  • junit5spring-4.3.12

    Jul 26, 2022
  • junit5spring-4.3.11

    Jul 07, 2022
  • junit5spring-4.3.10

    Jun 28, 2022
  • junit5spring-4.3.9

    May 31, 2022
  • junit5spring-4.1.38

    May 31, 2022
  • junit5spring-4.3.8

    May 26, 2022
  • junit5spring-4.1.37

    May 26, 2022
  • junit5spring-4.3.7

    May 13, 2022
  • junit5spring-4.2.21

    May 13, 2022
  • junit5spring-4.1.36

    May 13, 2022
  • junit5spring-4.4.0-beta.2

    Apr 27, 2022
  • junit5spring-4.1.35

    Apr 19, 2022
  • junit5spring-4.4.0-beta.1

    Apr 11, 2022
  • junit5spring-4.4.0-beta.0

    Mar 22, 2022
  • junit5spring-4.3.6

    Mar 22, 2022
  • junit5spring-4.3.5

    Feb 10, 2022
  • junit5spring-4.2.20

    Feb 10, 2022
  • junit5spring-4.1.34

    Feb 09, 2022
  • junit5spring-4.3.4

    Jan 12, 2022
  • junit5spring-4.2.19

    Jan 12, 2022
  • junit5spring-4.1.33

    Jan 12, 2022
  • junit5spring-4.3.3

    Jan 06, 2022
  • junit5spring-4.2.18

    Jan 06, 2022
  • junit5spring-4.1.32

    Jan 06, 2022
  • junit5spring-4.1.31

    Dec 09, 2021
  • junit5spring-4.2.17

    Dec 09, 2021
  • junit5spring-4.3.2

    Dec 09, 2021
  • junit5spring-4.2.16

    Dec 09, 2021
  • junit5spring-4.1.30

    Dec 08, 2021
  • junit5spring-4.3.1

    Nov 16, 2021
  • junit5spring-4.3.0

    Nov 12, 2021
  • junit5spring-4.2.15

    Nov 12, 2021
  • junit5spring-4.1.29

    Nov 12, 2021
  • junit5spring-4.3.0-beta.6

    Oct 18, 2021
  • junit5spring-4.3.0-beta.5

    Oct 10, 2021
  • junit5spring-4.3.0-beta.4

    Oct 05, 2021
  • junit5spring-4.2.14

    Oct 04, 2021
  • junit5spring-4.2.13

    Sep 27, 2021
  • junit5spring-4.1.28

    Sep 27, 2021
  • junit5spring-4.2.12

    Sep 19, 2021
  • junit5spring-4.1.27

    Sep 19, 2021
  • junit5spring-4.3.0-beta.3

    Sep 10, 2021
  • junit5spring-4.3.0-beta.2

    Sep 06, 2021
  • junit5spring-4.2.11

    Sep 04, 2021
  • junit5spring-4.1.26

    Sep 04, 2021
  • junit5spring-4.3.0-beta.1

    Aug 23, 2021
  • junit5spring-4.2.10

    Aug 22, 2021
  • junit5spring-4.1.25

    Aug 22, 2021
  • junit5spring-4.3.0-beta.0

    Aug 09, 2021
  • junit5spring-4.2.9

    Aug 01, 2021
  • junit5spring-4.1.24

    Aug 01, 2021
  • junit5spring-4.2.8

    Jul 21, 2021
  • junit5spring-4.2.7

    Jun 27, 2021
  • junit5spring-4.1.23

    Jun 24, 2021
  • junit5spring-4.1.22

    Jun 05, 2021
  • junit5spring-4.2.6

    May 23, 2021
  • junit5spring-4.1.21

    May 23, 2021
  • junit5spring-4.2.5

    May 09, 2021
  • junit5spring-4.2.4

    Apr 14, 2021
  • junit5spring-4.1.20

    Apr 11, 2021
  • junit5spring-4.2.3

    Mar 28, 2021
  • junit5spring-4.1.19

    Mar 28, 2021
  • junit5spring-4.2.2

    Mar 13, 2021
  • junit5spring-4.1.18

    Mar 13, 2021
  • junit5spring-4.2.1

    Mar 05, 2021
  • junit5spring-4.2.0

    Feb 11, 2021
  • junit5spring-4.1.17

    Feb 11, 2021
  • junit5spring-4.1.16

    Feb 02, 2021
  • junit5spring-4.2.0-beta.3

    Jan 25, 2021
  • junit5spring-4.1.15

    Jan 20, 2021
  • junit5spring-4.1.14

    Jan 10, 2021
  • junit5spring-4.2.0-beta.2

    Dec 28, 2020
  • junit5spring-4.1.13

    Dec 28, 2020
  • junit5spring-4.1.12

    Dec 13, 2020
  • junit5spring-4.1.11

    Nov 15, 2020
  • junit5spring-4.2.0-beta.1

    Nov 09, 2020
  • junit5spring-4.1.10

    Nov 06, 2020
  • junit5spring-4.2.0-beta.0

    Oct 18, 2020
  • junit5spring-4.1.9

    Oct 18, 2020
  • junit5spring-4.1.8

    Oct 14, 2020
  • junit5spring-4.1.7

    Aug 09, 2020
  • junit5spring-4.1.6

    Jul 03, 2020
  • junit5spring-4.1.5

    Jun 27, 2020
  • junit5spring-4.1.4

    Jun 19, 2020
  • junit5spring-4.1.3

    Jun 18, 2020
  • junit5spring-4.1.2

    Jun 15, 2020
  • junit5spring-4.1.1

    Jun 08, 2020
  • junit5spring-4.1.0

    May 20, 2020

How to add a dependency to Maven

Add the following au.com.dius.pact.provider : junit5spring maven dependency to the pom.xml file with your favorite IDE (IntelliJ / Eclipse / Netbeans):

<dependency>
    <groupId>au.com.dius.pact.provider</groupId>
    <artifactId>junit5spring</artifactId>
    <version>4.1.40</version>
</dependency>

How to add a dependency to Gradle

Gradle Groovy DSL: Add the following au.com.dius.pact.provider : junit5spring gradle dependency to your build.gradle file:

implementation 'au.com.dius.pact.provider:junit5spring:4.1.40'

Gradle Kotlin DSL: Add the following au.com.dius.pact.provider : junit5spring gradle kotlin dependency to your build.gradle.kts file:

implementation("au.com.dius.pact.provider:junit5spring:4.1.40")

How to add a dependency to SBT Scala

SBT Scala: Add the following au.com.dius.pact.provider : junit5spring sbt scala dependency to your build.sbt file:

libraryDependencies += "au.com.dius.pact.provider" % "junit5spring" % "4.1.40"