CBDE

Introduction to Unit Testing Smart Contracts

How to test smart contracts thoroughly before deployment: testing strategy and local networks, the Hardhat, Foundry and Remix frameworks (and Truffle in older material), writing assertions for state, events, reverts and balances, and using fixtures, time control, coverage and fuzzing.

  • 3 lessons
  • Module quiz

Because deployed contracts cannot be patched, tests are the main defence against bugs. This module explains testing strategy and frameworks, then shows how to write thorough tests with Hardhat and Solidity, and how to use fixtures, time control, coverage and fuzzing.

What the exam expects

Expect questions on where tests run, which framework does what (including Truffle in older material), and which assertion or helper fits a scenario: events, reverts, permissions, balance changes, deadlines and coverage.

How this module is organized

Testing Fundamentals and Frameworks covers what to test and the tools. Writing Unit Tests covers Mocha, Chai and Solidity tests. Fixtures, Time Control, Coverage and Fuzzing covers techniques for larger suites.

  1. Testing Fundamentals and Frameworks Lesson 1
  2. Writing Unit Tests Lesson 2
  3. Fixtures, Time Control, Coverage and Fuzzing Lesson 3
  4. Practise and review
  5. Checkpoint Practice activities across the module
  6. Test your knowledge 8 questions