Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

After unit tests fail, run a step / add a process to teardown

Lucas van Staden
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 31, 2018

As the title states.

Using phpunit, with selinium, headless chrome.

During unit tests, if any test fails, a screenshot is made of the issue. These are stores in a folder, which I want to upload to S3 bucket (as per existing guides), which would allow to see browser view at the point of test fail.

The issue I have is that teardown runs, after phpunit fails, which skips any further script actions.

I also tried to set the copy part as a second step, which also does not run.

 

So, is there a way to run steps/script actions prior/during teardown?

1 answer

1 accepted

2 votes
Answer accepted
Lucas van Staden
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 2, 2018

Solved.

My mistake was to run the unittest command directly in the pipeline yml

I created a bash script, which runs the unittests, capture the result.
If the result is a fail, I create a 'flag file' (tried to set an environment variable, but that did not work)

The bash script always exits with 0 (no error)

If the 'flag file' exists (in later steps) I can do needed actions

 

./vendor/phpunit/phpunit/phpunit --fail-on-warning --log-junit ./test-reports/junit.xml -c tests/phpunit.xml.dist --testsuite Admin
set RESULT=$?
if [ $RESULT -ne 0 ]; then
echo $RESULT >>./testdata/testfailed.txt
fi
exit 0

 

The last step in yml:

 

- if [ ! -f ${BITBUCKET_CLONE_DIR}/Magium/testdata/testfailed.txt ]; then /bin/true; else /bin/false; fi 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events