Testing with Solidity

As we mentioned before, Truffle enables us to run unit tests using Solidity as well as JavaScript. In order to start testing with Solidity, create a file called TontineTest.sol (.sol extension not .js) in Truffle’s test/ folder with the following code:

 import "truffle/Assert.sol"; import "../contracts/tontine.sol"; import "truffle/DeployedAddresses.sol"; contract TontineTest { }

This is an empty test contract, so we start by importing the needed testing libraries, DeployedAddresses.sol and Assert.sol (created dynamically at the time of deployment), along with the contract being tested (tontine.sol).

When we import external contracts, filenames are always treated as a path with "/" as the directory separator. All path ...

Get Blockchain By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.