Install act and docker:
curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
sudo apt update
sudo apt -y install docker.io
brew install act
brew install --cask docker
Create a personal access token.
Invoke the workflow:
act -W .github/workflows/unit-tests.yml -s GITHUB_TOKEN=[token]
-r, --reuse
to reuse the container.
Get a bash shell in the container, if needed:
docker ps
docker exec -it <container name> /bin/bash
-
The commands to build and run tests are in unit-tests.yml. For the queries on syntax please refer to the Workflow syntax for GitHub Actions.
-
External dependencies need to be mocked. For each external header, add one into the tests.cmake (preserve the original path parts, if needed). For each external declaration, add one into the mocks folder. For the queries on mocks please refer to the gMock Cookbook.
-
For the queries on how to write tests please refer to the GoogleTest User’s Guide. Common recommendations:
- Tests should be fast.
- Tests should be independent and repeatable.
- Find the smallest piece of logic you can test, isolate it from other parts.
- Use One-Assert-per-Test and Arrange-Act-Assert patterns. If two or more tests operate on similar data, use a test fixture.
- Having more constraints than necessary is bad.
If a test over-specifies, it doesn’t leave enough freedom to the implementation.
Use
ON_CALL
by default, and only useEXPECT_CALL
when intend to verify that the call is made.
-
Before review:
- Enable ClangFormat and make sure the tests code is formatted.
- Make sure the code builds without warnings.
- At the bottom of the workflow summary page on GitHub, there is a section with artifacts. Artifacts include coverage report and valgrind log. They help to understand how much code is covered by tests and whether there are memory leaks. Make sure you check both.