This document will help you learn about configuring NBomber tests, especially it covers the topic of dynamic configuration via config files. NBomber separate configuration on two types:

  • Test configuration: defines all kinds of settings related only for tests. It could be settings for load simulation, settings to choose target scenarios to run, duration of the test, database connection strings, etc.
/// Loads test configuration.
NBomberRunner.loadConfig "config.json"
  • Infrastructure configuration: defines all kinds of settings related only to infrastructure. It could be settings for the logger, plugins, etc.
/// Loads infrastructure configuration.
NBomberRunner.loadInfraConfig "infra-config.json"

Test configuration

NBomber provides a way to configure your test via JSON or YAML configuration files. Instead of hardcoding some values you can put them in the config and then load it. Take a look first on the configuration via NBomber API (F# or C#) and then choose your favorite format (JSON or YAML).

// scenario configuration
Scenario.create "hello_world" [step1; step2; step3]
|> Scenario.withWarmUpDuration(seconds 1)
|> Scenario.withoutWarmUp
|> Scenario.withLoadSimulations [
RampConstant(copies = 10, during = seconds 10)
KeepConstant(copies = 10, during = seconds 10)
RampPerSec(rate = 10, during = seconds 10)
InjectPerSec(rate = 10, during = seconds 10)
// nbomber runner configuration
|> NBomberRunner.registerScenario
|> NBomberRunner.registerScenarios [scenario1; scenario2]
|> NBomberRunner.withTestSuite "mongo_tests"
|> NBomberRunner.withTestName "insert_data"
|> NBomberRunner.withReportFileName "my_report"
|> NBomberRunner.withReportFormats [ReportFormat.Txt; ReportFormat.Csv; ReportFormat.Html; ReportFormat.Md]
|> NBomberRunner.withoutReports
|> NBomberRunner.withReportingSinks [influxDbSink; prometheusSink]
|> NBomberRunner.loadConfig "config.json" // or config.yaml
|> NBomberRunner.loadInfraConfig "infra_config.json" // or infra_config.yaml

Injecting custom settings

So far you have seen how you can configure NBomber tests via configuration files. But what if you want to extend your test by custom configuration settings. For example, you want to pass the SQL connection string for a database, and depending on the environment you want to pass different values.

"server=; uid=root; pwd=12345; database=test"

For such cases, NBomber provides dedicated configuration settings called Custom Settings where are you can put any object structure like this one:

"TestSuite": "nbomber_tests",
"TestName": "hello_world_test",
"TargetScenarios": ["hello_world_scenario"],
"GlobalSettings": {
"ScenariosSettings": [{
"ScenarioName": "hello_world_scenario",
"WarmUpDuration": "00:00:05",
"LoadSimulationsSettings": [
{ "RampConstant": [100, "00:00:50"] },
{ "KeepConstant": [100, "00:00:50"] },
{ "RampPerSec": [5, "00:00:05"] },
{ "InjectPerSec": [5, "00:00:05"] }
"CustomSettings": {
"Server": "",
"Uid": "root",
"Pwd": "12345",
"Database": "test"
"ConnectionPoolSettings": [
{ "PoolName": "web_socket_pool", "ConnectionCount": 5 }
"ReportFileName": "custom_report_name",
"ReportFormats": [ "Html", "Txt", "Csv", "Md" ]

And then fetch it into your test (make sure that your custom settings located within related scenario settings):

type SqlDbSettings = {
Server: string
Uid: string
Pwd: string
Database: string
let testInit = fun (context: ScenarioContext) -> task {
let settings = context.CustomSettings.DeserializeJson<SqlDbSettings>()
//let settings = context.CustomSettings.DeserializeYaml<SqlDbSettings>() // in case of yaml
context.Logger.Information("test init received CustomSettings.TestField '{TestField}'", settings.TestField)
Scenario.create "hello_world_scenario" [step1; step2]
|> Scenario.withTestInit(testInit)

Infrastracture configuration

CLI arguments