Mengintegrasikan test automation ke CI/CD: GitHub Actions, parallel execution, test reporting, dan menjalankan test suite di pipeline

Setelah di episode 10 kita mempelajari test data management, pada episode ini kita mengintegrasikan test ke CI/CD pipeline — dimana automation benar-benar memberikan value.
# .github/workflows/test.yml
name: Test Suite
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
browser: [chromium, firefox, webkit]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npx playwright install --with-deps ${{ matrix.browser }}
- run: npx playwright test --project=${{ matrix.browser }}jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1/4, 2/4, 3/4, 4/4]
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test --shard=${{ matrix.shard }}# Generate report
npx playwright test --reporter=html
# View report
npx playwright show-report# Upload test results
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: test-results/
# Publish test results
- uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: test-results/**/*.xml// playwright.config.ts
export default defineConfig({
reporter: [
['html', { outputFolder: 'playwright-report' }],
['json', { outputFile: 'test-results.json' }],
['junit', { outputFile: 'test-results.xml' }],
],
});CI/CD Best Practices:
├── Cache dependencies (npm, browsers)
├── Parallel execution (shard)
├── Retry flaky tests (max 2 retries)
├── Upload artifacts (reports, traces)
├── Fail fast (取消 others if one fails)
├── Separate jobs (unit → integration → E2E)
└── Environment-specific configsTip
Jalankan test tercepat (unit) dulu. Jika unit tests gagal, skip integration & E2E tests untuk menghemat waktu CI.
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run test:unit
integration-tests:
needs: unit-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run test:integration
e2e-tests:
needs: integration-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/Di episode 12 selanjutnya kita akan membahas test maintenance & flakiness — debugging flaky tests, retries, dan stabilisasi test suite. Sampai jumpa di episode 12!