Skip to content

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 xyz succeeded, report reports/xxx.xunit.xml was properly generated...) 

Design principles

The Node template has a `tests/` folder with all testing material:

  • 2 test projects, each with its own .gitlab-ci.yml file and Node specific material
  • the .gitlab-ci.yml includes the Node template(s) with the include:local keyword
  • a symbolic link templates/ points to the repository templates folder (the only way accepted by gitlab-ci-local)
  • each unit test is defined by one xxx.test.yml file, containing:
  • specific template configuration (second part, directly handled by gitlab-ci-local)
  • gitlab-ci-local specific configuration, tests metadata and asertions (pseudo code, not implemented yet)

How to run

Pre requisites

 Install:

  1. gitlab-ci-local first,
  2. Docker or Podman (⚠️ requires export 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:

  1.  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-local execution 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
  2. make sure this can be executed in GitLab CI/CD
Edited by Pierre Smeyers

Merge request reports

Loading