Skip to content

Commit 4300fa8

Browse files
committed
try pact in pipeline
1 parent 69220ba commit 4300fa8

3 files changed

Lines changed: 146 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,51 @@ jobs:
6262
run: |
6363
./mvnw -B spring-boot:run &
6464
ab -p src/test/resources/apachebench/create-customer-request.json -T application/json -c 10 -n 1000 http://localhost:8080/api/customers
65+
66+
pact-contract-tests:
67+
runs-on: ubuntu-24.04
68+
name: pact-contract-tests
69+
steps:
70+
- name: Checkout code
71+
uses: actions/checkout@v4
72+
73+
- name: Set up JDK
74+
uses: actions/setup-java@v4
75+
with:
76+
java-version: 21
77+
distribution: 'adopt'
78+
java-package: 'jdk'
79+
cache: 'maven'
80+
81+
- name: Start Pact Broker infrastructure
82+
run: docker compose --file spring-boot-example/docker-pact-broker-compose.yml up -d
83+
84+
- name: Wait for Pact Broker to be ready
85+
run: |
86+
echo "Waiting for Pact Broker to be ready..."
87+
for i in {1..30}; do
88+
if curl -f http://localhost:9292 > /dev/null 2>&1; then
89+
echo "Pact Broker is ready!"
90+
break
91+
fi
92+
echo "Waiting for Pact Broker... ($i/30)"
93+
sleep 2
94+
done
95+
96+
- name: Run consumer contract tests
97+
working-directory: spring-boot-example
98+
run: ./mvnw -B test -Dtest=StockApiContractTest
99+
100+
- name: Publish pacts to broker
101+
working-directory: spring-boot-example
102+
run: ./mvnw -B pact:publish
103+
104+
- name: Run provider verification tests
105+
working-directory: spring-boot-example
106+
run: ./mvnw -B test -Dtest=StockApiProviderTest
107+
108+
- name: Clean up Docker containers
109+
if: always()
110+
run: |
111+
docker compose --file spring-boot-example/docker-pact-broker-compose.yml down -v
112+
docker compose --file spring-boot-example/docker-compose.yml down -v

CLAUDE.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Repository Overview
6+
7+
This is the Java Testing Toolbox - a comprehensive educational repository demonstrating 30 testing tools and libraries for Java developers. The codebase contains practical examples for the book "30 Testing Tools & Libraries Every Java Developer Must Know".
8+
9+
## Architecture
10+
11+
### Module Structure
12+
- **spring-boot-example**: Main module containing most testing examples. Each testing tool has its own package under `src/test/java/de/rieckpil/blog/`
13+
- **jakarta-ee-example**: Demonstrates testing in Jakarta EE context, primarily MicroShed Testing
14+
15+
### Test Organization
16+
- Unit tests: `*Test.java` or `*Spec.groovy`
17+
- Integration tests: `*IT.java`
18+
- Web tests: `*WT.java`
19+
- Performance tests: Located in `gatling` package
20+
- All test examples are self-contained within their respective packages
21+
22+
## Essential Commands
23+
24+
### Spring Boot Example
25+
26+
```bash
27+
# Build and run all tests
28+
./mvnw verify
29+
30+
# Run unit tests only
31+
./mvnw test
32+
33+
# Run integration tests only
34+
./mvnw failsafe:integration-test
35+
36+
# Run specific test class
37+
./mvnw test -Dtest=UserRegistrationServiceTest
38+
39+
# Start the application (requires Docker)
40+
docker-compose up -d
41+
./mvnw spring-boot:run
42+
43+
# Run Gatling performance tests (requires running application)
44+
./mvnw gatling:test
45+
46+
# Run mutation testing
47+
./mvnw pitest:mutationCoverage
48+
49+
# Generate JGiven reports
50+
./mvnw jgiven:report
51+
```
52+
53+
### Jakarta EE Example
54+
55+
```bash
56+
# Build and run all tests
57+
./mvnw verify
58+
59+
# Run unit tests only
60+
./mvnw test
61+
62+
# Run integration tests
63+
./mvnw failsafe:integration-test
64+
65+
# Start Liberty server
66+
./mvnw liberty:run
67+
```
68+
69+
## Key Testing Patterns
70+
71+
### Test Infrastructure
72+
73+
- **Testcontainers**: Used extensively for integration tests requiring databases or external services
74+
- **Docker Compose**: Provides PostgreSQL and other services for local development
75+
- **MockWebServer/WireMock**: For mocking external HTTP services
76+
- **LocalStack**: For testing AWS services locally
77+
78+
### Testing Frameworks Coverage
79+
80+
The repository demonstrates these testing categories:
81+
82+
1. Test Runners: JUnit 4/5, TestNG, Spock
83+
2. Assertions: AssertJ, Hamcrest, JsonPath, XMLUnit, JSONAssert
84+
3. Mocking: Mockito, WireMock, MockWebServer
85+
4. Integration: Testcontainers, REST Assured, MicroShed Testing
86+
5. Web Testing: Selenium, Selenide
87+
6. Performance: Gatling, JMH, JfrUnit
88+
7. Contract Testing: Pact
89+
8. Architecture Testing: ArchUnit
90+
91+
### Important Conventions
92+
93+
- Java 21 is required for all modules
94+
- Docker must be running for integration tests
95+
- Test output is redirected to files in CI/CD environments
96+
- Each testing tool example is isolated in its own package
97+
- Examples demonstrate real-world usage patterns, not just basic syntax

spring-boot-example/src/test/java/de/rieckpil/blog/pact/StockApiProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package au.com.dius.pactworkshop.provider;
1+
package de.rieckpil.blog.pact;
22

33
import au.com.dius.pact.provider.junit5.HttpTestTarget;
44
import au.com.dius.pact.provider.junit5.PactVerificationContext;

0 commit comments

Comments
 (0)