Draft: TBC unit-testing proof of concept
This is a Proof of Concept of using gitlab-ci-local to implement TBC (unit) tests:
- add one or several mininal test project material in the template repo (ex: mini Node test project in the Node template repo)
- a single unit test involves:
- a test project
- some specific template configuration (ex: enable feature A, disable feature B, override default param C...)
- run
gitlab-ci-local - verify some assertions (ex: job
xyzsucceeded, reportreports/xxx.xunit.xmlwas properly generated...)
Design principles
The Node template has a `tests/` folder with all testing material:
- 2 test projects, each with its own
.gitlab-ci.ymlfile and Node specific material - the
.gitlab-ci.ymlincludes the Node template(s) with the include:local keyword - a symbolic link
templates/points to the repository templates folder (the only way accepted bygitlab-ci-local) - each unit test is defined by one
xxx.test.ymlfile, containing: - specific template configuration (second part, directly handled by
gitlab-ci-local) -
gitlab-ci-localspecific configuration, tests metadata and asertions (pseudo code, not implemented yet)
How to run
Pre requisites
Install:
- gitlab-ci-local first,
- Docker or Podman (
⚠️ requiresexport GCL_CONTAINER_EXECUTABLE=podman).
Run unit tests
# run first test (⚠️ --variables-file is relative to --cwd)
gitlab-ci-local --cwd tests/prj-yarn-1 --variables-file ../build-yarn-ok.test.yml
# run second test (⚠️ --variables-file is relative to --cwd)
gitlab-ci-local --cwd tests/prj-npm-1 --variables-file ../build-npm-ok.test.yml
What's next?
Starting from this Proof of Concept, we can imagine the following:
- developing a Node-based unit testing framework:
- uses and automates gitlab-ci-local as a library (instead of a CLI program),
- grab all the
gitlab-ci-localexecution context (executed jobs, their status, stdout/stderr...) into a data structure that can easily be used with an assertion library - select the most appropriate assertion library
- select the most appropriate Node unit test framework
- make sure this can be executed in GitLab CI/CD
Edited by Pierre Smeyers