Building test networks
When testing your plugin code, you may want to reproduce different scenarios to check that everything works as expected for different networks.
In the Qatium testing library we created some helper utilities to create your own networks. This section will guide you on how to build test networks, the available helpers and example networks ready to use.
A simple network
For Qatium’s testing library, a network is an array of assets connected with each other. Let’s say for example we want to create the following network:
In this network we have a Supply Source SS1
, connected to a Junction J1
with a Valve V1
in between connected with two Pipes P1, P2
.
So, in order to create this network we can do the following:
As you can see we defined all the assets in our network with their connections between them.
When instantiating a mocked SDK using mockSDK, you are only required to specify the type for each asset of your network, the rest of the properties will be populated with defaults. If you need to, you can also override any of the asset properties specified on the asset page:
Networks that can not be simulated
When instantiating a mocked SDK using the mockSDK API we can pass a network and a simulation mode. If we choose to simulate mockSDK({ network, simulationMode: "simulate" })
we will run an actual simulation of the network. It may happen that we build a network that does not have a proper simulation result.
So, imagine we want to test out a network with just a Junction:
We will get the following error: no tanks or reservoirs in network
.
So, if you want to test out this network, you have two options:
- Fix the network for it to simulate correctly. For instance, adding a Supply Source and a pipe connected to the junction.
- Use a different simulation mode.
Example networks
In addition to building your own networks, you can use some of the example networks built in the SDK testing library. All example networks can be used in both simulation and non-simulation test modes, and let you test many use cases for your plugin.
To access them, import the ExampleNetworks
object from your test as in this example:
Here’s the list of example networks available in the SDK testing library: