...

/

Unit Testing in Solidity Using Remix Tests

Unit Testing in Solidity Using Remix Tests

Learn to write unit tests for a smart contract to ensure its functionality.

The code and software we develop often have loopholes or do not run as intended. They might exhibit negative or unexpected behaviors. Smart contracts are no different. We want to avoid this, if possible, because these contracts frequently deal with money and sensitive information, and once they’re deployed, they can’t be modified. This is why we vigorously test our contracts and try to keep these unwanted behaviors to a minimum.

Setting up

Remix offers us the opportunity to test our contracts using the Solidity Unit Testing plugin. This plugin is already activated when we create a new workspace in Remix. We can confirm this by the presence of a double check mark on the left panel of the IDE.

Press + to interact
Double check mark icon confirms test plugin activation
Double check mark icon confirms test plugin activation

If we don’t see this icon, it means the test plugin is deactivated. To enable it, navigate to the plugin manager screen by clicking the plug icon on the bottom of the left panel. Do a search for “unit testing,” and then activate the plugin in the results list.

Once the plugin is activated, we can move ahead with the setup. All tests will be stored in a root folder called tests. If we have this directory already, with test files from previous ...