4

Is there a way to run individual tests in forge? looking for a behavior similar to '.only' in mocha

3 Answers 3

3

Yes you can!

You can use forge test --match-contract $YourContractName or even forge test --match where, for exemple, if you use --match mint, forge will execute all tests that have 'mint' in their function name.

Hope this helps!

2
  • Is there a way we can do forge test --match-contract $YourContractName --match <FunctionName> I want to test specific function of this contract
    – Dakata
    Aug 29, 2023 at 13:09
  • this might help forge test --match-test yourFunctionName book.getfoundry.sh/… Sep 27, 2023 at 19:36
3

For individual tests i use:

 forge test --match-path test/functional/**/$(TEST_NAME)\*

This runs TEST_NAME in any subfolder after the the path test/functional

1

In case you want to just test a specific function try this:

forge test --match-test yourFunctionName

For more visit foundry faq

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.