Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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: '17'

- name: Compile
run: |
mkdir -p src
javac -cp lib/junit-platform-console-standalone-1.11.4.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.11.4.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=12

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."
1 change: 1 addition & 0 deletions command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
javac -cp lib/junit-platform-console-standalone-1.11.4.jar src/*.java && java -jar lib/junit-platform-console-standalone-1.11.4.jar -cp src --scan-classpath
2 changes: 1 addition & 1 deletion src/PasswordUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
public class PasswordUtilsTest {
@Test
void testDescribePasswordLengthShortPassword() {

//
}
}