foundry-rs / book

A book on all things Foundry, available at https://book.getfoundry.sh.
https://book.getfoundry.sh
Apache License 2.0
807 stars 642 forks source link

Suggestion to change test naming best practices #1279

Closed milosdjurica closed 1 month ago

milosdjurica commented 1 month ago

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 :

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.

My suggestion is to change best practices from example above to ->

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.

zerosnacks commented 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