How does Gitlab CI determine if a PHPUnit test pass or fails?
I have this basic .gitlab-ci.yml
file.
image: php:7.2
before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install
tests:
script:
- vendor/bin/phpunit tests
This works just fine, it alerts me if unit tests fail or pass.
My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES!
exist?
php unit-testing continuous-integration gitlab devops
add a comment |
I have this basic .gitlab-ci.yml
file.
image: php:7.2
before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install
tests:
script:
- vendor/bin/phpunit tests
This works just fine, it alerts me if unit tests fail or pass.
My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES!
exist?
php unit-testing continuous-integration gitlab devops
A script returning any other exit code than 0 is treat as failed.
– Sascha Frinken
Jan 2 at 22:07
@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is justTests: 1, Assertions: 1, Failures: 1
orOK (1 test, 1 assertion)
– IMB
Jan 3 at 6:33
php.net/manual/en/function.exit.php
– Sascha Frinken
Jan 3 at 7:20
@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.
– IMB
Jan 3 at 7:36
Your unit test is just a script that will return0
as exit code when all tests pass. CI checks the return code and handles it as failed or passed.
– Sascha Frinken
Jan 3 at 7:42
add a comment |
I have this basic .gitlab-ci.yml
file.
image: php:7.2
before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install
tests:
script:
- vendor/bin/phpunit tests
This works just fine, it alerts me if unit tests fail or pass.
My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES!
exist?
php unit-testing continuous-integration gitlab devops
I have this basic .gitlab-ci.yml
file.
image: php:7.2
before_script:
# install git
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install
tests:
script:
- vendor/bin/phpunit tests
This works just fine, it alerts me if unit tests fail or pass.
My question is how exactly does Gitlab CI know this? Do they parse the output of PHPUnit and see if the string FAILURES!
exist?
php unit-testing continuous-integration gitlab devops
php unit-testing continuous-integration gitlab devops
asked Jan 2 at 14:37
IMBIMB
4,350124389
4,350124389
A script returning any other exit code than 0 is treat as failed.
– Sascha Frinken
Jan 2 at 22:07
@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is justTests: 1, Assertions: 1, Failures: 1
orOK (1 test, 1 assertion)
– IMB
Jan 3 at 6:33
php.net/manual/en/function.exit.php
– Sascha Frinken
Jan 3 at 7:20
@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.
– IMB
Jan 3 at 7:36
Your unit test is just a script that will return0
as exit code when all tests pass. CI checks the return code and handles it as failed or passed.
– Sascha Frinken
Jan 3 at 7:42
add a comment |
A script returning any other exit code than 0 is treat as failed.
– Sascha Frinken
Jan 2 at 22:07
@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is justTests: 1, Assertions: 1, Failures: 1
orOK (1 test, 1 assertion)
– IMB
Jan 3 at 6:33
php.net/manual/en/function.exit.php
– Sascha Frinken
Jan 3 at 7:20
@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.
– IMB
Jan 3 at 7:36
Your unit test is just a script that will return0
as exit code when all tests pass. CI checks the return code and handles it as failed or passed.
– Sascha Frinken
Jan 3 at 7:42
A script returning any other exit code than 0 is treat as failed.
– Sascha Frinken
Jan 2 at 22:07
A script returning any other exit code than 0 is treat as failed.
– Sascha Frinken
Jan 2 at 22:07
@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just
Tests: 1, Assertions: 1, Failures: 1
or OK (1 test, 1 assertion)
– IMB
Jan 3 at 6:33
@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just
Tests: 1, Assertions: 1, Failures: 1
or OK (1 test, 1 assertion)
– IMB
Jan 3 at 6:33
php.net/manual/en/function.exit.php
– Sascha Frinken
Jan 3 at 7:20
php.net/manual/en/function.exit.php
– Sascha Frinken
Jan 3 at 7:20
@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.
– IMB
Jan 3 at 7:36
@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.
– IMB
Jan 3 at 7:36
Your unit test is just a script that will return
0
as exit code when all tests pass. CI checks the return code and handles it as failed or passed.– Sascha Frinken
Jan 3 at 7:42
Your unit test is just a script that will return
0
as exit code when all tests pass. CI checks the return code and handles it as failed or passed.– Sascha Frinken
Jan 3 at 7:42
add a comment |
1 Answer
1
active
oldest
votes
The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.
Ok so if I have a home-brewed tester script I simplyecho 1;
orecho 0;
for pass and fails?
– IMB
Jan 3 at 16:10
No,echo
does only print to stdout string you pass to it. For passing and failing CI it would beexit 0
andexit 1
.
– Azaradel
Jan 3 at 16:12
You mean literately usingexit(0);
orexit(1);
– IMB
Jan 3 at 16:17
Yes. My example was from bash that's why it is without brackets.
– Azaradel
Jan 3 at 16:19
I see that. Never knewexit();
had a special purpose other than terminating the script execution.
– IMB
Jan 3 at 16:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008227%2fhow-does-gitlab-ci-determine-if-a-phpunit-test-pass-or-fails%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.
Ok so if I have a home-brewed tester script I simplyecho 1;
orecho 0;
for pass and fails?
– IMB
Jan 3 at 16:10
No,echo
does only print to stdout string you pass to it. For passing and failing CI it would beexit 0
andexit 1
.
– Azaradel
Jan 3 at 16:12
You mean literately usingexit(0);
orexit(1);
– IMB
Jan 3 at 16:17
Yes. My example was from bash that's why it is without brackets.
– Azaradel
Jan 3 at 16:19
I see that. Never knewexit();
had a special purpose other than terminating the script execution.
– IMB
Jan 3 at 16:23
add a comment |
The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.
Ok so if I have a home-brewed tester script I simplyecho 1;
orecho 0;
for pass and fails?
– IMB
Jan 3 at 16:10
No,echo
does only print to stdout string you pass to it. For passing and failing CI it would beexit 0
andexit 1
.
– Azaradel
Jan 3 at 16:12
You mean literately usingexit(0);
orexit(1);
– IMB
Jan 3 at 16:17
Yes. My example was from bash that's why it is without brackets.
– Azaradel
Jan 3 at 16:19
I see that. Never knewexit();
had a special purpose other than terminating the script execution.
– IMB
Jan 3 at 16:23
add a comment |
The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.
The gitlab-ci only checks the exit codes of processes running inside it. If a process exits with another status code than 0 then the pipeline stops and declares failure. That's how the CI pipelines works overall, not only gitlab but Jenkins, etc. too.
answered Jan 3 at 15:29
AzaradelAzaradel
1213
1213
Ok so if I have a home-brewed tester script I simplyecho 1;
orecho 0;
for pass and fails?
– IMB
Jan 3 at 16:10
No,echo
does only print to stdout string you pass to it. For passing and failing CI it would beexit 0
andexit 1
.
– Azaradel
Jan 3 at 16:12
You mean literately usingexit(0);
orexit(1);
– IMB
Jan 3 at 16:17
Yes. My example was from bash that's why it is without brackets.
– Azaradel
Jan 3 at 16:19
I see that. Never knewexit();
had a special purpose other than terminating the script execution.
– IMB
Jan 3 at 16:23
add a comment |
Ok so if I have a home-brewed tester script I simplyecho 1;
orecho 0;
for pass and fails?
– IMB
Jan 3 at 16:10
No,echo
does only print to stdout string you pass to it. For passing and failing CI it would beexit 0
andexit 1
.
– Azaradel
Jan 3 at 16:12
You mean literately usingexit(0);
orexit(1);
– IMB
Jan 3 at 16:17
Yes. My example was from bash that's why it is without brackets.
– Azaradel
Jan 3 at 16:19
I see that. Never knewexit();
had a special purpose other than terminating the script execution.
– IMB
Jan 3 at 16:23
Ok so if I have a home-brewed tester script I simply
echo 1;
or echo 0;
for pass and fails?– IMB
Jan 3 at 16:10
Ok so if I have a home-brewed tester script I simply
echo 1;
or echo 0;
for pass and fails?– IMB
Jan 3 at 16:10
No,
echo
does only print to stdout string you pass to it. For passing and failing CI it would be exit 0
and exit 1
.– Azaradel
Jan 3 at 16:12
No,
echo
does only print to stdout string you pass to it. For passing and failing CI it would be exit 0
and exit 1
.– Azaradel
Jan 3 at 16:12
You mean literately using
exit(0);
or exit(1);
– IMB
Jan 3 at 16:17
You mean literately using
exit(0);
or exit(1);
– IMB
Jan 3 at 16:17
Yes. My example was from bash that's why it is without brackets.
– Azaradel
Jan 3 at 16:19
Yes. My example was from bash that's why it is without brackets.
– Azaradel
Jan 3 at 16:19
I see that. Never knew
exit();
had a special purpose other than terminating the script execution.– IMB
Jan 3 at 16:23
I see that. Never knew
exit();
had a special purpose other than terminating the script execution.– IMB
Jan 3 at 16:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008227%2fhow-does-gitlab-ci-determine-if-a-phpunit-test-pass-or-fails%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A script returning any other exit code than 0 is treat as failed.
– Sascha Frinken
Jan 2 at 22:07
@SaschaFrinken Can you kindly explain in brief what exit codes are in relation to PHPUnit? Do you mean to say PHPUnit internally returns 0 or 1? How does Gitlab CI read it? The output of PHPUnit for a human is just
Tests: 1, Assertions: 1, Failures: 1
orOK (1 test, 1 assertion)
– IMB
Jan 3 at 6:33
php.net/manual/en/function.exit.php
– Sascha Frinken
Jan 3 at 7:20
@SaschaFrinken I'm aware of that but my question is how does that relate to Gitlab CI? It seems it magically knows if the tests fails or pass. What if I'm using a home-brewed or private testing software, I want to know how Gitlab CI would know if I'm returning a pass or fail test.
– IMB
Jan 3 at 7:36
Your unit test is just a script that will return
0
as exit code when all tests pass. CI checks the return code and handles it as failed or passed.– Sascha Frinken
Jan 3 at 7:42