feat: Enforce test requirements - fail pipeline if no tests
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 34s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m7s
API Gateway (Java Spring Boot) / test (17) (push) Failing after 1m17s
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 22s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 47s
API Gateway (Java Spring Boot) / test (21) (push) Failing after 2m45s
API Gateway (Java Spring Boot) / build (push) Has been skipped
API Gateway (Java Spring Boot) / security (push) Has been skipped
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m46s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Integration Tests / integration-tests (push) Failing after 2m22s
Integration Tests / performance-tests (push) Has been skipped
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 34s
LabFusion CI/CD Pipeline / api-gateway (push) Failing after 1m7s
API Gateway (Java Spring Boot) / test (17) (push) Failing after 1m17s
LabFusion CI/CD Pipeline / service-adapters (push) Failing after 22s
LabFusion CI/CD Pipeline / api-docs (push) Successful in 47s
API Gateway (Java Spring Boot) / test (21) (push) Failing after 2m45s
API Gateway (Java Spring Boot) / build (push) Has been skipped
API Gateway (Java Spring Boot) / security (push) Has been skipped
LabFusion CI/CD Pipeline / frontend (push) Failing after 1m46s
LabFusion CI/CD Pipeline / integration-tests (push) Has been skipped
Integration Tests / integration-tests (push) Failing after 2m22s
Integration Tests / performance-tests (push) Has been skipped
## Test Requirements Enforcement ### 1. Remove Dummy Test Report Fallback - Removed dummy test report creation - Pipeline will now fail if no test reports are generated - Ensures proper test coverage requirements ### 2. Early Test File Validation - Added 'Check for test files' step before test execution - Counts test files in src/test/java/ directory - Sets TEST_FILES_EXIST environment variable ### 3. Fail Fast for Missing Test Files - Added 'Fail if no test files exist' step - Fails pipeline immediately if no test files found - Provides clear guidance on test file requirements - Shows example of proper test file naming ### 4. Enhanced Test Report Validation - Added 'Fail if no test reports found' step - Fails pipeline if no test reports are generated after test execution - Provides detailed error messages explaining possible causes - Ensures test execution actually produces reports ### 5. Clear Error Messages - Specific guidance on test file naming conventions - Examples of proper test file structure - Clear indication of what's required for pipeline success ## Pipeline Behavior - **Fails early** if no test files exist - **Fails** if tests don't generate reports - **Provides clear guidance** on test requirements - **Enforces test coverage** as a quality gate ## Expected Results - Pipeline will fail if no test files are present - Pipeline will fail if test execution doesn't produce reports - Clear error messages guide developers to add proper tests - Ensures all code changes include corresponding tests
This commit is contained in:
@@ -63,6 +63,33 @@ jobs:
|
||||
- name: Compile code
|
||||
run: ./mvnw compile
|
||||
|
||||
- name: Check for test files
|
||||
run: |
|
||||
echo "Checking for test files in src/test/java/..."
|
||||
if [ -d "src/test/java" ]; then
|
||||
TEST_COUNT=$(find src/test/java -name "*Test*.java" -type f | wc -l)
|
||||
echo "Found $TEST_COUNT test files"
|
||||
if [ $TEST_COUNT -eq 0 ]; then
|
||||
echo "⚠️ No test files found! Please add test files to src/test/java/"
|
||||
echo "TEST_FILES_EXIST=false" >> $GITHUB_ENV
|
||||
else
|
||||
echo "✅ Test files found"
|
||||
echo "TEST_FILES_EXIST=true" >> $GITHUB_ENV
|
||||
fi
|
||||
else
|
||||
echo "❌ No src/test/java directory found!"
|
||||
echo "TEST_FILES_EXIST=false" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Fail if no test files exist
|
||||
if: env.TEST_FILES_EXIST == 'false'
|
||||
run: |
|
||||
echo "❌ No test files found in src/test/java/"
|
||||
echo "This pipeline requires test files to be present."
|
||||
echo "Please add test files with names ending in 'Test.java' or 'Tests.java'"
|
||||
echo "Example: src/test/java/com/labfusion/MyServiceTest.java"
|
||||
exit 1
|
||||
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
echo "Running Maven tests..."
|
||||
@@ -98,19 +125,6 @@ jobs:
|
||||
echo "TEST_REPORTS_EXIST=false" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Create dummy test report if none exists
|
||||
if: env.TEST_REPORTS_EXIST == 'false'
|
||||
run: |
|
||||
echo "Creating dummy test report since no tests were found..."
|
||||
cat > target/surefire-reports/TEST-dummy.xml << 'EOF'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuite name="DummyTest" tests="1" failures="0" errors="0" skipped="0" time="0.001">
|
||||
<testcase name="dummyTest" classname="DummyTest" time="0.001"/>
|
||||
</testsuite>
|
||||
EOF
|
||||
echo "Dummy test report created"
|
||||
echo "TEST_REPORTS_EXIST=true" >> $GITHUB_ENV
|
||||
|
||||
- name: Generate test report
|
||||
uses: dorny/test-reporter@v1
|
||||
if: env.TEST_REPORTS_EXIST == 'true'
|
||||
@@ -118,6 +132,18 @@ jobs:
|
||||
name: Maven Tests (Java ${{ matrix.java-version }})
|
||||
path: target/surefire-reports/*.xml
|
||||
reporter: java-junit
|
||||
|
||||
- name: Fail if no test reports found
|
||||
if: env.TEST_REPORTS_EXIST == 'false'
|
||||
run: |
|
||||
echo "❌ No test reports were generated!"
|
||||
echo "This indicates that either:"
|
||||
echo "1. No test files were found in src/test/java/"
|
||||
echo "2. Tests failed to execute properly"
|
||||
echo "3. Maven Surefire plugin did not generate reports"
|
||||
echo ""
|
||||
echo "Please ensure you have test files and they are executing correctly."
|
||||
exit 1
|
||||
|
||||
- name: Run code quality checks
|
||||
run: |
|
||||
|
||||
Reference in New Issue
Block a user