Side Quest 5 - Adding CI features with Github Actions
I appreciated the github action in the juice-shop repo that published test results to the repo’s github pages and wanted to have the same feature in the security-testing repo (the SerenityBDD tests for Juice Shop).
Publishing test results
All I had to do was add the github-deploy-action to .github/workflows/maven.yml:
- name: Test Report on GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4.7.3
if: github.ref == 'refs/heads/main'
with:
branch: gh-pages
folder: target/site/serenity
clean: true
- name: Link to Results
run:
echo "[Test Results](https://softwaretestingcentre.github.io/security-testing/)" >> $GITHUB_STEP_SUMMARY
And change the Settings/Actions/General/Workflow Permissions for the repo to read/write:
And now every time I push to the repo, the tests run and publish the results to the repo’s github pages.
Which is much easier than downloading them as an artifact and opening them locally.
Creating a test summary
The publish-unit-test-result-action can provide a nice summary on the workflow run page when the tests have finished.
I added the config to the same workflow file
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: (!cancelled())
with:
files: |
target/failsafe-reports/*CucumberTestSuite.xml
The tests ran and produced a summary. I pushed a new test:
Scenario: Haxxor reads the privacy policy
Given Haxxor goes to the Juice Shop
When she opens the Privacy Policy
Then she sees she has solved the "Privacy Policy" challenge
and this updated the results:
✔️ You can see that it compares the results to the previous run, picking up the fact that we have a new test
Then I deliberately broke the test and pushed it again:
Then she sees she has solved the "Reflected XSS" challenge
And the failing test is named in the summary:
✔️ If you click on the test name, it takes you to the commit, so you can see what changed.
✔️ The Test Results link in the sidebar lets you drill in to see the error:
After we fix the test, we can see the effect on the results: