Bash unit tests
Run tests with the Bash testing framework and publish their results in the GitLab test summary. The default CI Tools tools image includes bashunit; a custom image must provide Bash and bashunit on PATH.
Run Bash tests
Include common and bashunit in .gitlab-ci.yml:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/bashunit@stable
Add tests/example_test.sh:
function test_adds_numbers() {
assert_equals 5 "$((2 + 3))"
}
The test:bashunit job discovers *_test.sh files below the repository root. It runs their tests and uploads bashunit-junit.xml, including assertion failures. A failed test fails the job by default. A missing test directory or a pattern matching no files also fails the job.
Select test files
Use path and pattern to select another directory or file name pattern:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/bashunit@stable
inputs:
path: tests/unit
pattern: "*Test.sh"
junit-report: reports/bashunit.xml
rules:
- exists:
- "tests/unit/*Test.sh"
when: on_success
- when: never
Change rules when changing the file name pattern: the default rule checks for **/*_test.sh. Relative report paths start at the project root. The report is retained for one week and uploaded even when assertions fail. Invalid discovery paths fail before a report is created.
Use name, image, stage, needs, allow-failure, and rules to configure the job, as with python-unittest. The separate bash-unit-tests component runs standalone *.ci-test.sh scripts; use bashunit for tests written with bashunit assertions.
Inputs
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| allow-failure | Should the pipeline continue when one or more tests fail? | false | boolean |
| image | The image used to run the tests. | ${CI_TOOLS_REPO}/tools:${CI_TOOLS_COMPONENT_VERSION} | string |
| junit-report | Path to the JUnit report shown in the GitLab test summary. | bashunit-junit.xml | string |
| name | The name of the test job. | bashunit | string |
| needs | The jobs that this job depends on. | [] | array |
| path | The directory to search for Bash test files. | . | string |
| pattern | The file name pattern used to discover Bash test files. | *_test.sh | string |
| rules | The rules for the test job. | [{"exists":["**/*_test.sh"],"when":"on_success"},{"when":"never"}] | array |
| stage | The stage for the test job. | test | string |