Junior — Middle
How can you set up automatic test execution using GitLab CI/CD?
sobes.tech AI
Answer from AI
To set up automatic test runs in GitLab CI/CD, you need to create a .gitlab-ci.yml file in the root of your repository, where you define stages and jobs for running tests.
Example of a simple config for a Java project with Maven:
stages:
- test
test_job:
stage: test
script:
- mvn test
tags:
- runner-tag
Explanation:
stagesdefines the sequence of stages, here onlytest.test_jobis a job that runs at theteststage.- In
script, commands for running tests are specified. tagsare optional, if you have GitLab Runners configured with tags.
After pushing to the repository, GitLab will automatically start the pipeline, execute tests, and display the result in the interface. You can extend the config by adding build, deploy, and other stages.