Is it a good practice to create modifier
s in Foundry test
s?
When testing cases, that share significant number of steps, but not that much that you want to create a separate testContract for them, with its own setUp()
. (A simplistic situation could be testing a token contract where test
s approve
steps for testing allowance
, transfer
and other cases.)
I couldn't see any use of modifier
s in examples linked by Foundry, so it raised this question: is it "safe" (in broad sense), is it a good practice at all?
Best Answer
It is safe to use modifiers in tests, but I cannot speak to whether it is good practice or not. It definitely does not seem to be common practice.
The main reason we have not used modifiers in example code is that it might seem a little opaque for example code, not because it won't work :)