2

I am working on Gitlab and I would like to set up a CI (it is the first time I configure something like that, please assume that I am a beginner)

I wrote a code in C with a simple test in Cunit, I configured CI with a "build" job and a "test" job. My test job succeed whereas I wrote a KO test, when I open the job on Gitlab I see the failed output, but the job is marked "Passed".

How can I configure Gitlab to understand that the test failed ?

I think there is a parsing configuration somewhere, I tried in "CI / CD Setting -> Test coverage parsing" but I think it is wrong, and it did not work.

I let you the output of my test :

     CUnit - A unit testing framework for C - Version 2.1-2
     http://cunit.sourceforge.net/


Suite: TEST SUITE FUNCTION
  Test: Test of function::triple ...FAILED
    1. main.c:61  - CU_ASSERT_EQUAL(triple(3),1)

Run Summary:    Type  Total    Ran Passed Failed Inactive<br/>
              suites      1      1    n/a      0        0<br/>
               tests      1      1      0      1        0<br/>
             asserts      3      3      2      1      n/a<br/>

Elapsed time =    0.000 seconds
Efren
  • 4,003
  • 4
  • 33
  • 75
lefel
  • 23
  • 3
  • Did you try exiting with non-0 ? – marcolz Nov 02 '17 at 08:24
  • Hi marcolz, Thanks, indeed I did solething lke that tout solve my issue : I wrote a script where I run my test executable and put the output in a temporary file, then I grep the string I am searching for ("...FAILED" for instance), and I test the output code of grep with the variable $? to know if the string was found , and finaly remove my temporary file and exit a non-zero status if found. – lefel Nov 03 '17 at 09:26
  • 1
    At the end of `int main()` where you have called CUnit, you can return with the CUnit result using `return CU_get_number_of_tests_failed();` See: http://cunit.sourceforge.net/doxdocs/group__Framework.html#ga52 – ahogen Dec 17 '19 at 23:44

1 Answers1

0

Gitlab supports test reports in JUnit format and coverage reports in cobertura XML format

See the links for C++ examples that may help you, as an example for CUnit, the .gitlab_ci.yaml file should look like:

cunit:
  stage: test
  script:
    - ./my-cunit-test
  artifacts:
    when: always
    reports:
      junit: ./my-cunit-test.xml
Efren
  • 4,003
  • 4
  • 33
  • 75