Skill 6.1.2
Compare smart contract testing frameworks
Key Concepts
Hardhat 3 runs two kinds of test with npx hardhat test. Solidity tests are contracts whose test-prefixed functions call the contract under test; they are compatible with Foundry's syntax and support fuzzing. JavaScript or TypeScript tests use Mocha with Chai and ethers.js (the mocha-ethers toolbox), or Node.js's built-in test runner with viem. Network helpers and Chai matchers support fixtures, time travel, events, reverts and balance changes.
Foundry is a Rust toolkit whose forge test runs Solidity tests very quickly, with cheatcodes such as vm.prank (call as another address), vm.expectRevert, vm.warp (set the time) and vm.deal (set a balance), and built-in fuzz and invariant testing. The Remix Solidity Unit Testing plugin runs Solidity test contracts that use the remix_tests.sol Assert library, directly in the browser.
Truffle, the framework most 2018-era material describes, ran truffle test with JavaScript tests in contract() blocks (Mocha with Chai) and Solidity tests, against Ganache. ConsenSys sunset Truffle and Ganache in 2023, recommending migration to Hardhat.