Closed milosdjurica closed 1 month ago
Thanks for your suggestion!
In practice I've noticed that most non-unit tests cover multiple functions in non-isolation
I think for unit tests it is fine to add the function name, for other types of tests this is not practical
The general recommendations still stand, but consider the function name optional
Marking as not planned
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.