🎓 A1Learner
🔍
0 of 50 lessons completed

GitHub Actions: Running Tests on Every Push

A test workflow runs the tests on every push. A push that breaks a test turns the run red at once.

Trigger on push

This trigger runs the workflow on every push.

on: push

The Node test job

This job checks out the code, sets up Node, and runs the tests.

node-tests:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v7
    - uses: actions/setup-node@v7
      with:
        node-version: '24'
    - run: npm test

The Python test job

This job checks out the code, sets up Python, installs pytest, and runs the test.

python-tests:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v7
    - uses: actions/setup-python@v7
      with:
        python-version: '3.13'
    - run: pip install pytest
    - run: pytest test_app.py

Example

name: Tests

on: push

jobs:
  node-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
      - run: npm test
  python-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-python@v7
        with:
          python-version: '3.13'
      - run: pip install pytest
      - run: pytest test_app.py

Key points

  • Tests run on the runner, not on the reader's own machine.
  • on: push makes the workflow run on every push.
  • One workflow can hold two jobs, one per language.
  • The Node job runs npm test.
  • The Python job runs pytest.
  • A job that fails marks the whole run red.
  • The same pipeline shape works for both languages. Only the setup action and the test command change.
  • Testing on every push catches a break at the push that caused it.

In this example, the workflow runs on every push. It holds two jobs. The Node job runs npm test, and both Node tests pass. The Python job installs pytest and runs the Python test, which passes. A broken test in either job would turn the run red.

Note

The demo tests are small. Two Node tests and one Python test.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What makes a test workflow run on every push?