Test Profiles
Test Profiles let you use different settings to run your Solidity tests. For example, you might use one Test Profile while iterating locally and another in CI, each with the number of fuzz runs that suits that workflow.
Configuring a Test Profile
Section titled “Configuring a Test Profile”To configure a Test Profile, use this extended version of the test.solidity settings in your config:
import { defineConfig } from "hardhat/config";
export default defineConfig({ //... test: { solidity: { profiles: { default: { fuzz: { runs: 256 }, }, ci: { fuzz: { runs: 10_000 }, }, }, }, },});Each Test Profile can use the full Solidity tests configuration.
When using profiles, a default profile is always required.
Profile names can contain letters, numbers, underscores, and dashes. They can’t be fuzz, invariant, isolate, evmVersion, or allowInternalExpectRevert, as those would be ambiguous with inline configuration keys.
If you define your Solidity tests config without explicitly defining Test Profiles, you’re actually configuring the default behavior.
Choosing a Test Profile
Section titled “Choosing a Test Profile”Use the --test-profile argument to choose which Test Profile to use when running your tests.
For example, to run your Solidity tests with the ci profile:
npx hardhat test solidity --test-profile cipnpm hardhat test solidity --test-profile ciyarn hardhat test solidity --test-profile ciIt also works on the test task, where it only affects the Solidity tests:
npx hardhat test --test-profile cipnpm hardhat test --test-profile ciyarn hardhat test --test-profile ciSet the HARDHAT_TEST_PROFILE environment variable to select a profile:
HARDHAT_TEST_PROFILE=ci npx hardhat testHARDHAT_TEST_PROFILE=ci pnpm hardhat testHARDHAT_TEST_PROFILE=ci yarn hardhat testIf you provide both, the argument takes precedence. If you don’t specify a profile, Hardhat uses default.
Sharing default values between Test Profiles
Section titled “Sharing default values between Test Profiles”To use the same settings in several profiles, define them once in your config file and spread them into each profile:
import { defineConfig } from "hardhat/config";
const base = { isolate: true, fuzz: { runs: 256 },};
export default defineConfig({ //... test: { solidity: { profiles: { default: base, ci: { ...base, fuzz: { runs: 10_000 } }, }, }, },});Each Test Profile is resolved on its own, starting from Hardhat’s defaults, the same way Build Profiles are. A profile that only sets fuzz.runs gets the default value for every other setting, not the value from default.
Test Profiles and Build Profiles
Section titled “Test Profiles and Build Profiles”Test Profiles and Build Profiles are independent: Test Profiles only affect how your tests run, and Build Profiles only affect how your contracts are compiled.
Switching Test Profiles doesn’t cause your contracts to be recompiled, so you can switch between profiles freely. If you want to change both profiles, you need to pass both arguments:
npx hardhat test --build-profile production --test-profile cipnpm hardhat test --build-profile production --test-profile ciyarn hardhat test --build-profile production --test-profile ciOverriding settings for a single test
Section titled “Overriding settings for a single test”Test Profiles apply to your entire test suite. To override settings for a single test function, use inline configuration, which can also be scoped to a Test Profile.