Is it a good practice to create modifiers in Foundry tests?

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 tests approve steps for testing allowance, transfer and other cases.)

I couldn't see any use of modifiers in examples linked by Foundry, so it raised this question: is it "safe" (in broad sense), is it a good practice at all?

1 Answer 1


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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.