Skip to content

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.

To configure a Test Profile, use this extended version of the test.solidity settings in your config:

hardhat.config.ts
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.

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:

Terminal window
npx hardhat test solidity --test-profile ci

It also works on the test task, where it only affects the Solidity tests:

Terminal window
npx hardhat test --test-profile ci

Set the HARDHAT_TEST_PROFILE environment variable to select a profile:

Terminal window
HARDHAT_TEST_PROFILE=ci npx hardhat test

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

hardhat.config.ts
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 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:

Terminal window
npx hardhat test --build-profile production --test-profile ci

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.