Skill 6.2.3
Use fixtures, time manipulation, coverage and fuzzing
Key Concepts
A fixture is a function that sets up a known state, such as deploying contracts and minting tokens. Hardhat's networkHelpers.loadFixture(deployFixture) runs it once, takes a snapshot of the chain, and restores that snapshot for each later test, which is much faster than redeploying and guarantees isolation between tests.
Network helpers control the chain: networkHelpers.time.increase(3600) advances the clock by an hour and mines a block, time.increaseTo(t) jumps to a timestamp, mine(n) mines blocks, and impersonateAccount and setBalance act as, or fund, any address. These are essential for deadlines, vesting schedules and auctions.
npx hardhat test --coverage reports the lines and branches executed by tests, pointing to untested logic. Fuzz tests are Solidity test functions with parameters, which the runner calls with many random values to find edge cases. Coverage and fuzzing complement, but do not replace, carefully written assertions.