forge Testing
Solidity tests.
Tests Are Contracts
In Foundry a test file is a Solidity contract that inherits from Test in the forge-std library. Each public function whose name starts with test is run as an individual test case.
Test files live in test/ and conventionally use the .t.sol suffix.
import {Test} from "forge-std/Test.sol";
contract CounterTest is Test {
function testInitialZero() public {
// ...
}
}The setUp Function
The special setUp() function runs before every test, giving each test a fresh, isolated state. Deploy your contracts and seed any fixtures here.
Because state resets between tests, one test can never accidentally depend on another.
Counter counter;
function setUp() public {
counter = new Counter();
}