A mobile client can test its API expectations without calling a live movie service. The Pact JUnit 5 package integrates Pact setup with JUnit Jupiter: annotating a test class with PactConsumerTestExt starts a mock server and checks that required test elements are present. section 5.2
Use it for consumer logic tests, alongside the Android app’s test folder. A @Pact function identifies the provider and consumer, then returns a V4Pact contract whose interactions describe the request and expected response. section 5.2
Movie API consumer test
A MoviesApiPactTest uses @ExtendWith(PactConsumerTestExt::class) and PER_CLASS lifecycle. Its contract expects GET /movies when “a movie exists,” then returns 200, an application/json header, and an array of movie id, name, and year fields. A @PactTestFor test receives MockServer, points MovieClient at its URL, calls getMovies(), and asserts a nonempty response. section 5.2
Figure 5.6 Pact interaction contains the mobile app’s actual request intercepted and the expected response returned from the mock server. Finally, the interactions are converted to a Pact file.
Follow the interaction from the client request through the mock-server response to conversion into a Pact file. section 5.2
