forked from auberonedu/centroid-finder
-
Notifications
You must be signed in to change notification settings - Fork 12
49 lines (40 loc) · 1.46 KB
/
run-tests.yml
File metadata and controls
49 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: JUnit Tests
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '23'
- name: Compile
run: |
mkdir -p src
javac -cp lib/junit-platform-console-standalone-1.12.0.jar src/*.java
- name: Run and Verify Tests
run: |
# Ensure that the pipeline fails if any command fails.
set -o pipefail
# Run tests and tee output to both the console and a file.
java -jar lib/junit-platform-console-standalone-1.12.0.jar -cp src --scan-classpath | tee test-results.txt
# Capture the exit code of the java command.
exit_code=${PIPESTATUS[0]}
if [ $exit_code -ne 0 ]; then
echo "❌ Unit tests failed with exit code $exit_code."
exit $exit_code
fi
# Extract the number of tests run from the output.
TEST_COUNT=$(grep -oP '\d+(?= tests found)' test-results.txt | head -n 1)
MIN_TESTS=15
if [ "$TEST_COUNT" -lt "$MIN_TESTS" ]; then
echo "❌ Only $TEST_COUNT tests were run. At least $MIN_TESTS tests are required. Please write more unit tests"
exit 1
fi
echo "✅ All unit tests passed and $TEST_COUNT tests were executed."