Sobes.tech
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:

  • stages defines the sequence of stages, here only test.
  • test_job is a job that runs at the test stage.
  • In script, commands for running tests are specified.
  • tags are 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.