Lab: free tools · size first · stock scanner · crypto scanner · journal
Foundry Forge Test Explained: Solidity Testing with the Forge Test Runner
Forge is the test runner component of the Foundry development framework. It executes Solidity-based tests extremely fast using a Rust-implemented EVM, supports fuzz testing and invariant testing natively, provides detailed gas reports, and includes mainnet forking for integration tests. Forge has become the preferred testing tool for security researchers and professional DeFi developers.
Foundry is a fast toolkit for Ethereum smart-contract development, and Forge is its testing tool. Tests are written in Solidity itself, which means developers do not switch languages, and Forge supports fuzzing, invariant testing and forking mainnet state to test against real protocols. A strong Forge test suite is one of the better signs that a team cares about correctness, though it does not replace an independent audit.
What a Forge test looks like
Tests are Solidity contracts, and any function whose name starts with test runs as a test. Forge gives tests cheatcodes that bend the environment: prank sets who the caller is, warp moves the block timestamp, deal hands an address a balance, and expectRevert asserts that the next call fails the right way. A function that takes arguments becomes a fuzz test, and Forge feeds it random inputs, with bound used to keep values in a sensible range. Invariant tests go further. They call functions in random order and check after each step that a rule still holds, such as total deposits always covering total withdrawals.
Testing against real state
With createSelectFork a test can copy the state of mainnet at a chosen block and run against real contracts and real balances. That's how teams check an integration with a lending market or a DEX before shipping. forge coverage shows which lines the tests touched, forge snapshot records gas use per test, and mutation testing checks whether the suite would notice if the code were quietly changed.
What it tells an outsider
A repository packed with fuzz and invariant tests, run on every change, is a decent sign. Tests still only check what someone thought to write down, and many expensive exploits came from cases nobody pictured. That's why fuzzing and invariants matter more than a long list of simple unit tests, and why an outside audit still belongs on top.