diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..d980d63 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -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." diff --git a/command.md b/command.md new file mode 100644 index 0000000..e7e2a69 --- /dev/null +++ b/command.md @@ -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 \ No newline at end of file diff --git a/src/PasswordUtilsTest.java b/src/PasswordUtilsTest.java index a5350b8..9372694 100644 --- a/src/PasswordUtilsTest.java +++ b/src/PasswordUtilsTest.java @@ -4,6 +4,6 @@ public class PasswordUtilsTest { @Test void testDescribePasswordLengthShortPassword() { - +// } }