# Test infrastructure and execution

This tutorial shows you how to set up your components for testing, loading all the resources required for the tests, and starting up the basic services.

## Test Infrastructure

We recommend you create a testing directory structure beside your source code with the following directory structure to create a division between the application code and the tests for it.

![verifier_testdir](../../../images/verifier_testdir.JPG)

Here, _novox_ is the root package name of your JavaScript namespace. You should create a parallel test class file(s) for every class you wish to test.

### JsTestDriver.conf file

The example **_jsTestDriver.conf_** file (shown below) runs tests from all the JavaScript files in the _tests_ directory (inside _test-unit_).

```js
server: http://localhost:4224
basepath: .
plugin:
  - name: "BundleInjector"
  jar: ../../../../../../../../sdk/libs/java/testRunner/js-test-driver-bundler-plugin.jar
  module: com.caplin.jstestdriver.plugin.CutlassBundleInjectorPlugin
load:
  - bundles/js/js.bundle
test:
  - tests/*.js
```

**📌 NOTE**\
A _jsTestDriver.conf_ file is created automatically when you create a new bladeset or blade (within a bladeset). It should be noted that these files are not the same. They are created at different levels in the directory hierarchy, so the number of `../` in the `jar:` line will be different.

### Additional bundles

By default the generated _jsTestDriver.conf_ files exclude three of the four available bundles. To include the _internationalisation_, _html_ and _xml_ bundles, you must add the following:

```
load: 
  - bundles/i18n/en_i18n.bundle
serve:
  - bundles/html.bundle
  - bundles/xml.bundle
```

When the tests are run, a _bundles_ directory will be created by [_BladeRunner_](../bladerunner/index.md) under the relevant _js-test-driver_ directory containing the required bundles as shown:

![verifier_testdir_bundles](../../../images/verifier_testdir_bundles.JPG)

### Service Registry

In order to enable your test to use these bundles, besides adding these to the _jsTestDriver.conf_ file, you must also load them into the correct application services. For example the **_xml.bundle_** needs to be accessible to the `[XmlResourceService,opts="nofollow"](https://docs.caplin.com/developer/api/caplin_trader/3/caplin.services.xmlresourceservice)`:

```js
if (!caplin.core.ServiceRegistry.isServiceRegistered("br.xml-service")) {
  var oXmlResourceService = new caplin.services.providers.CaplinXmlResourceService("/test/bundles/xml.bundle");
  caplin.core.ServiceRegistry.registerService("br.xml-service", oXmlResourceService);
}
```

The relevant XML can then be accessed correctly by the test and by the system under test:

```js
var oXmlResourceService = caplin.core.ServiceRegistry.getService ("br.xml-service");
var eTradeModelNode = oXmlResourceService.getXmlDocument("tradeModels");
```

## Test Execution

The easiest way to execute a test is via the _BladeRunner_ **dashboard**. Simply launch the application dashboard and click on "Run tests" for the blade in question. This will look at the _jsTestDriver.conf_ file of the acceptance and unit tests for that blade, and will execute the tests specified in that file.

![verifier_testexecution](../../../images/verifier_testexecution.jpg)

Alternatively you may select which tests to run via the command line. Simply navigate to the _BladeRunner sdk_ directory and use the `bladerunner test` command. For example:

* To execute all (unit and acceptance) tests for an app:

  ```
  bladerunner test ..\apps\{app_name}
  ```
* To run unit tests at a bladeset level:

  ```
  bladerunner test ..\apps\{app_name}\{bladeset_name} UTs
  ```
* To run acceptance tests at a blade level:

  ```
  bladerunner test ..\apps\{app_name}\{bladeset_name}\blades\{blade_name} ATs
  ```

The test types are `ATs` (to run acceptance tests), `UTs` (to run the unit tests) or `ALL` (the default, to run both acceptance and unit tests).
