You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Foundry book under Best Practices it is suggested that if we "Have a Test contract per contract-under-test", then we should name our unit tests like this :
Citing the docs :
contract MyContractTest holds all unit tests for MyContract.
function test_add_AddsTwoNumbers() lives within MyContractTest to test the add method.
function test_supply_UsersCanSupplyTokens() also lives within MyContractTest to test the supply method.
I came to the conclusion that general approach is: test_FunctionName_Description
But later in the docs, when best practices are mentioned, FunctionName part is not used.
test_Description for standard tests.
testFuzz_Description for fuzz tests.
test_Revert[If|When]_Condition for tests expecting a revert.
testFork_Description for tests that fork from a network.
testForkFuzz_Revert[If|When]_Condition for a fuzz test that forks and expects a revert.
My suggestion is to change best practices from example above to ->
test_FunctionName_Description for standard tests.
testFuzz_FunctionName_Description for fuzz tests.
test_FunctionName_Revert[If|When]_Condition for tests expecting a revert.
testFork_FunctionName_Description for tests that fork from a network.
testForkFuzz_FunctionName_Revert[If|When]_Condition for a fuzz test that forks and expects a revert.
When user is testing multiple functions in a single test, he should omit FunctionName part and name the test like this : test_Description (old/current way of naming tests).
I think this would provide more clarity to the test naming conventions and it would make it easier to filter tests.
This way user can filter tests only for a specific function AND/OR tests that RevertIf , etc etc... forge test --mt FunctionName , forge test --mt RevertIf , forge test --mt FunctionName_RevertIf , all those comands work as expected.
The text was updated successfully, but these errors were encountered:
In the Foundry book under Best Practices it is suggested that if we "Have a Test contract per contract-under-test", then we should name our unit tests like this :
Citing the docs :
contract MyContractTest
holds all unit tests forMyContract
.function test_add_AddsTwoNumbers()
lives withinMyContractTest
to test theadd
method.function test_supply_UsersCanSupplyTokens()
also lives withinMyContractTest
to test thesupply
method.I came to the conclusion that general approach is:
test_FunctionName_Description
But later in the docs, when best practices are mentioned,
FunctionName
part is not used.test_Description
for standard tests.testFuzz_Description
for fuzz tests.test_Revert[If|When]_Condition
for tests expecting a revert.testFork_Description
for tests that fork from a network.testForkFuzz_Revert[If|When]_Condition
for a fuzz test that forks and expects a revert.My suggestion is to change best practices from example above to ->
test_FunctionName_Description
for standard tests.testFuzz_FunctionName_Description
for fuzz tests.test_FunctionName_Revert[If|When]_Condition
for tests expecting a revert.testFork_FunctionName_Description
for tests that fork from a network.testForkFuzz_FunctionName_Revert[If|When]_Condition
for a fuzz test that forks and expects a revert.When user is testing multiple functions in a single test, he should omit
FunctionName
part and name the test like this :test_Description
(old/current way of naming tests).I think this would provide more clarity to the test naming conventions and it would make it easier to filter tests.
This way user can filter tests only for a specific function AND/OR tests that
RevertIf
, etc etc...forge test --mt FunctionName
,forge test --mt RevertIf
,forge test --mt FunctionName_RevertIf
, all those comands work as expected.The text was updated successfully, but these errors were encountered: