0Pricing
Web3 & DApp Development Fundamentals · Lesson

Writing Tests

Mocha and Chai.

Why Test Contracts

Smart contracts are immutable once deployed and often hold real value. A single bug can be unrecoverable, so thorough testing is essential.

  • Catch logic errors before deployment.
  • Document expected behavior.
  • Guard against regressions when refactoring.

Mocha and Chai

Hardhat uses Mocha as the test runner and Chai for assertions, both included in the Toolbox.

  • describe groups related tests.
  • it defines a single test case.
  • expect makes assertions about values.

Tests live in the test/ folder.

All lessons in this course

  1. Writing Tests
  2. Testing Reverts and Events
  3. Coverage and Gas Reports
  4. Fixtures
← Back to Web3 & DApp Development Fundamentals