# Verifier Hello World

The purpose of a unit test is to test a single class in isolation. Below is an example of a unit of code and an example of a test you would write to verify that the code is correct.

To understand where to put your tests relative to your code, and about how to execute tests, first read [Test Infrastructure and Execution](verifier-test-infrastructure.md).

## Code

The example below returns a message if a value is not provided. Otherwise it returns the original value.

```js
novox.ValueUnavailableFormatter = function() {
  this.sMessage = "Value not supplied";
};

novox.ValueUnavailableFormatter.prototype.format = function(vValue) {
  if(vValue === null || vValue === undefined) {
    return this.sMessage;
  }
  else {
    return vValue;
  }
};
```

## Test

You declare a new test by instantiating a _TestCase_, passing it the unique name of your test. You use prototype declarations to create test methods.

```js
ValueUnavailableFormatterTest = TestCase("ValueUnavailableFormatterTest");

ValueUnavailableFormatterTest.prototype.setUp = function() {
  this.m_oFormatter = new novox.ValueUnavailableFormatter(sMessageLabel);
};

ValueUnavailableFormatterTest.prototype.test_NullInputReturnsMessage = function() {
  var sResult = this.m_oFormatter.format(null);
  assertEquals(sResult, "Value not supplied");
};

ValueUnavailableFormatterTest.prototype.tearDown = function() {
  this.m_oFormatter = undefined;
};
```

To be recognized and run as a test by _JSTestDriver,_ the function name must be prefixed with `test`. The `setUp()` method is executed before every test method. It is used to create objects that are required by all tests. The `tearDown()` method is used to return the browser to the same state that it was in before the test ran. This ensures tests do not interfere with each other.

### Executing Your Test

You execute your test by opening a console terminal and navigating to the _sdk_ directory of your _BladeRunnerJS_ installation. Then type the following command:

```
brjs test {aspect/bladeset/blade_path} UTs
```
