Skip to main content

JSON Configuration

This document will help you learn about configuring NBomber tests via configuration files. NBomber supports two types of configuration:

note

Config file has higher priority over code script configuration. For example, if you specified WarmUpDuration in both: code and the config file, NBomber will take the value from the config file.

Load Test Configuration#

Load test configuration allows you to set or override settings related to your load test. This type of configuration is represented as a JSON object with a strictly defined structure. Please refer to the following link to see the full corresponding JSON model.

Let's consider a basic example of a load test configuration file.

config.json
{
"TestSuite": "public_api_test_suite",
"TestName": "purchase_api_test",
"TargetScenarios": ["purchase_api"],
"GlobalSettings": {
"ScenariosSettings": [
{
"ScenarioName": "purchase_api",
"WarmUpDuration": "00:00:05",
"LoadSimulationsSettings": [
{ "InjectPerSec": [100, "00:00:15"] },
{ "InjectPerSec": [200, "00:00:15"] }
],
"CustomSettings": {
"BaseUri": "https://jsonplaceholder.typicode.com"
}
}
]
}
}

In order to load such config into NBomber test, you should use NBomberRunner.loadConfig. After this, NBomber will apply the loaded configuration.

NBomberRunner.loadConfig "config.json"

Test name settings#

You can set TestName and TestSuite of your NBomber test via the configuration file.

config.json
{
"TestSuite": "public_api_test_suite",
"TestName": "purchase_api_test",
}

Target scenario settings#

You can register all scenarios you have for your test but run only those you are interested in by setting TargetScenarios property in the configuration file. Thus, you can configure your NBomber tests dynamically by choosing the needed configuration file. Please note, if no TargetScenarios property is set in the configuration file, all registered scenarios will run.

config.json
{
"TargetScenarios": ["scenario1"]
}

The main usage of this setting is to specify which scenarios should be executed. For example you registered a few scenarios:

NBomberRunner.registerScenarios [insert_mongo; read_mongo; update_mongo]

And for one test you want to run the only insert_mongo but for the second one read_mongo and update_mongo together. You can achive this by using TargetScenario setting. One file will contain only insert_mongo scenario.

target_scenario_1.json
{
"TargetScenarios": ["insert_mongo"]
}

And second one will contain read_mongo and update_mongo together (they will be executed in parallel).

target_scenario_2.json
{
"TargetScenarios": ["read_mongo", "update_mongo"]
}

So the final thing is to load them into NBomber.

NBomberRunner.registerScenarios [insert_mongo; read_mongo; update_mongo]
|> NBomberRunner.loadConfig "target_scenario_1.json"
// |> NBomberRunner.loadConfig "target_scenario_2.json"

Also, you can specify path to config file via console arguments

Scenarios settings#

You can configure ScenariosSettings in GlobalSettings section of the configuration file.

config.json
{
"GlobalSettings": {
"ScenariosSettings": [
{
"ScenarioName": "scenario1",
"WarmUpDuration": "00:00:05",
"LoadSimulationsSettings": [
{ "KeepConstant": [100, "00:00:30"] },
{ "KeepConstant": [200, "00:00:15"] }
]
}
]
}
}

Client factory settings#

You can configure ClientFactorySettings for a scenario in GlobalSettings.ScenariosSettings section of the configuration file.

config.json
{
"GlobalSettings": {
"ScenariosSettings": [
{
"ScenarioName": "rest_api",
"ClientFactorySettings": [
{ "FactoryName": "websocket_factory", "ClientCount": 100 }
]
}
]
}
}

Reporting settings#

You can configure reporting settings by setting the following properties in GlobalSettings section of the configuration file.

config.json
{
"GlobalSettings": {
"ReportFileName": "my_report_name",
"ReportFolder": "./my_reports",
"ReportFormats": [ "Html", "Md", "Txt", "Csv" ],
"SendStatsInterval": "00:00:05"
}
}

Custom settings#

Custom settings allow injecting into test scenario user-defined settings. For example, depending on the environment where you run your tests, you want to use different SQL connections or target host addresses. Especially for such use cases, NBomber provides a way to inject any structured JSON object into your scenario and then fetch it and parse it based on a user-defined structure.

Let's imagine that we want to inject different URI to test the target host based on the environment.

config.json
{
"GlobalSettings": {
"ScenariosSettings": [
{
"ScenarioName": "rest_api",
"CustomSettings": {
"TargetHostUri": "https://jsonplaceholder.typicode.com"
}
}
]
}
}

Ok, let's try to fetch it into our scenario and parse it to get values. First, we need to define a type to represent CustomSettings.

[<CLIMutable>]
type CustomScenarioSettings = {
TargetHostUri: string
}

After this, we should add a handler on ScenarioInit to fetch CustomSettings related to a specific scenario. Finally, CustomSettings is fetched via ScenarioContext.CustomSettings.

[<CLIMutable>]
type CustomScenarioSettings = {
TargetHostUri: string
}
let buildScenario () =
let scenarioInit (context: IScenarioContext) = task {
let customSettings <- context.CustomSettings.Get<CustomScenarioSettings>()
// customSettings.TargetHostUri - you can get parsed value
context.Logger.Information($"test init received CustomSettings: {customSettings}")
}
Scenario.create "rest_api" [step]
|> Scenario.withInit scenarioInit

Hints analyzer settings#

You can enable or disable HintsAnalyzer in the GlobalSettings section of the configuration file.

config.json
{
"GlobalSettings": {
"UseHintsAnalyzer": false
}
}

Infrastructure Configuration#

Infrastructure configuration allows you to set or override options related to infrastructure: Logger, WorkerPlugin, ReportingSink (for example: Serilog logger, InfluxDb reporting sink, Ping plugin, etc). This type of configuration is represented as a JSON object with a structure not strictly defined by NBomber but rather by plugin or reporting sink.

Let's consider a basic example of an infrastructure configuration file.

infra-config.json
{
"Serilog": {
"WriteTo": [{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://localhost:9200",
"indexFormat": "nbomber-index-{0:yyyy.MM}"
}
}]
},
"PingPlugin": {
"Hosts": ["jsonplaceholder.typicode.com"],
"BufferSizeBytes": 32,
"Ttl": 128,
"DontFragment": false,
"Timeout": 1000
},
"InfluxDBSink": {
"Url": "http://localhost:8086",
"Database": "default"
}
}

In order to load such config into NBomber test, you should use NBomberRunner.loadInfraConfig. After this, NBomber will apply the loaded configuration.

Program.fs
NBomberRunner.loadInfraConfig "infra-config.json"