Unit tests¶
Goal
Learn how to...
- execute unit tests
- publish results in GitLab
This exercise adds a unit test to the hello world application.
Preparation¶
Let's update the code:
Task: Publish unit test results¶
The following commands execute unit tests and automatically convert the results to JUnit using gotestsum:
See the official documentation for special artifacts and specifically reports.
Add a job unit_test
to the stage check
containing the above commands. The job needs to define a special artifact from the file report.xml
so that GitLab recognizes it as as JUnit XML report.
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run which shows the unit test results on the tab in the overview.
Hint (Click if you are stuck)
GitLab has published an example. The unit test report is published using a special type of artifact:
Solution (Click if you are stuck)
.gitlab-ci.yml
:
If you want to jump to the solution, execute the following command: