Skip to content

Commit 0ecfdc0

Browse files
authored
Merge pull request #23 from hmcts/chore/amp-187-api_tests
AMP-187 Run api tests as part of the pipeline for pull requests
2 parents 4cedead + 9e4f6fb commit 0ecfdc0

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

.github/workflows/ci-build-publish.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ on:
2323
trigger_deploy:
2424
required: true
2525
type: boolean
26+
run_api_test:
27+
required: false
28+
type: boolean
29+
default: false
2630

2731

2832
jobs:
@@ -85,6 +89,43 @@ jobs:
8589
name: app-jar
8690
path: build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar
8791

92+
api-test:
93+
if: ${{ inputs.run_api_test }}
94+
needs: [Build]
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Checkout repository
98+
uses: actions/checkout@v6
99+
100+
- name: Set up JDK
101+
uses: actions/setup-java@v5
102+
with:
103+
distribution: 'temurin'
104+
java-version: '21'
105+
106+
- name: Set up Gradle
107+
uses: gradle/actions/setup-gradle@v5
108+
with:
109+
gradle-version: current
110+
111+
- name: Set up Docker Buildx
112+
uses: docker/setup-buildx-action@v3
113+
114+
- name: Run API Tests
115+
run: |
116+
cd apiTest
117+
gradle test
118+
119+
- name: Upload test reports
120+
if: always()
121+
uses: actions/upload-artifact@v6
122+
with:
123+
name: api-test-reports
124+
path: |
125+
apiTest/build/reports/tests/test/
126+
apiTest/build/test-results/test/
127+
128+
88129
Provider-Deploy:
89130
needs: [ Artefact-Version, Build ]
90131
runs-on: ubuntu-latest

.github/workflows/ci-draft.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ jobs:
2121
is_publish: ${{ github.event_name == 'push' }}
2222
trigger_docker: ${{ github.event_name == 'push' }}
2323
trigger_deploy: ${{ github.event_name == 'push' }}
24+
run_api_test: ${{ github.event_name == 'pull_request' }}

apiTest/apiTest_README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ Before running the tests, ensure you have the following installed and configured
4040
cd apiTest
4141

4242
# Run all tests
43-
../gradlew test
43+
gradle test
4444

4545
# Run tests with more verbose output
46-
../gradlew test --info
46+
gradle test --info
4747

4848
# Run tests with debug output
49-
../gradlew test --debug
49+
gradle test --debug
5050
```
5151

5252
### From the apiTest Directory
5353

5454
```bash
5555
# If you're already in the apiTest directory
56-
../gradlew test
56+
gradle test
5757
```
5858

5959
### What Happens When You Run Tests
@@ -71,10 +71,10 @@ cd apiTest
7171

7272
```bash
7373
# Run a specific test class
74-
../gradlew test --tests "RootApiTest"
74+
gradle test --tests "RootApiTest"
7575

7676
# Run a specific test method
77-
../gradlew test --tests "RootApiTest.root_endpoint_should_be_ok"
77+
gradle test --tests "RootApiTest.root_endpoint_should_be_ok"
7878
```
7979

8080
## Test Reports
@@ -102,15 +102,15 @@ These XML reports are useful for CI/CD integration.
102102
### Issue: "Could not start Gradle Test Executor 1: Failed to load JUnit Platform"
103103

104104
**Solution:** This should be resolved with the current configuration. If you see this error:
105-
1. Clean the build: `../gradlew clean`
106-
2. Rebuild: `../gradlew build`
105+
1. Clean the build: `gradle clean`
106+
2. Rebuild: `gradle build`
107107

108108
### Issue: "no main manifest attribute, in /app/apiTest-0.0.999.jar"
109109

110110
**Solution:** This means the Docker build context is wrong. Ensure:
111111
1. The `docker-compose.yml` has `context: ..` (builds from root directory)
112112
2. The root project's `bootJar` is built before Docker build
113-
3. Run: `../gradlew buildRootBootJar` manually if needed
113+
3. Run: `gradle buildRootBootJar` manually if needed
114114

115115
### Issue: Container exits with code 1
116116

apiTest/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ dockerCompose {
7979
tasks.register('buildRootBootJar', Exec) {
8080
description = "Builds the root project's bootJar"
8181
workingDir = projectDir.parent
82-
executable = "${projectDir.parent}/gradlew"
82+
executable = "gradle"
8383
args = ['bootJar']
8484
}
8585

0 commit comments

Comments
 (0)