Solidity Unit Tests via a GitHub Action
This GitHub action can run Solidity Unit Tests as part of your continuous integration and deployment process.
When coding a project, shifting the Solidity Unit Tests (SUT) to the GitHub side of things can optimize your workflow. Every time a push to the repo is made, the SUTs will run. Having Solidity Unit Tests run automatically on GitHub is one less thing to think about.
Adding Remix’s Solidity Unit Tests Action to your GitHub workflow is simple!
Check the GitHub Actions page for the Solidity Unit Tests Action.
- In your repo make a directory called .github/workflows
- In that directory, make a .yml file like the one below.
- In the example below, the action will look through the sample/tests directory, and will check for files named with a _test.sol suffix (e.g. filename_test.sol) and will run those tests.
- Change the name of the sample/tests directory to make it fit with your repo’s structure.
- If you don’t want to put a folder path, give the full path to a test file.
- Set the compiler version to be the same as the one in the contract files.
name: A job to run sample solidity tests
- name: Checkout
- name: Run SUT Action
Learn to write Solidity Unit Tests
The one prerequisite to using this action is knowing how to write Solidity unit tests. Check our testing docs here. You can play with these tests right in Remix, either by activating the Solidity Unit Tests plugin in the Remix Plugin Manager, or just by clicking here. In addition, you can try out these tests locally using our NPM package.
As you can see, its easy to set up the GitHub Action, so try it out!