2019-01-13 21:25:15 -06:00
|
|
|
+++
|
2019-02-25 19:02:23 -06:00
|
|
|
title = "Testing Helpers"
|
2019-01-13 21:25:15 -06:00
|
|
|
weight = 3
|
|
|
|
sort_by = "weight"
|
|
|
|
in_search_index = true
|
|
|
|
+++
|
|
|
|
|
|
|
|
The UCG testing modules can be imported like so `let t = import "std/testing.ucg";`
|
|
|
|
It has a number of helpful assertions you can use in unit testing.
|
|
|
|
|
|
|
|
## The asserts modules
|
|
|
|
|
|
|
|
### ok assertion
|
|
|
|
|
|
|
|
The `ok` assertion module tests that something is true. It has two parameters.
|
|
|
|
|
|
|
|
* `test` which is required and is represents the expression to test.
|
|
|
|
* `desc` which is an optional description to output for your test. This defaults to
|
2019-04-09 21:16:19 -05:00
|
|
|
the `todo_desc` that is set in the testing library.
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
```
|
2019-04-09 21:16:19 -05:00
|
|
|
let t = import "std/testing.ucg";
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
assert t.ok{
|
|
|
|
test=true,
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
### no_ok assertion
|
|
|
|
|
|
|
|
The `not_ok` assertion module tests that something is not true. It has two
|
|
|
|
parameters.
|
|
|
|
|
|
|
|
* `test` which is required and is represents the expression to test.
|
|
|
|
* `desc` which is an optional description to output for your test. This defaults to
|
2019-04-09 21:16:19 -05:00
|
|
|
the `todo_desc` that is set in the testing library.
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
```
|
2019-04-09 21:16:19 -05:00
|
|
|
let t = import "std/testing.ucg";
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
assert t.ok{
|
|
|
|
test=true,
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
### equal assertion
|
|
|
|
|
2019-01-13 22:06:38 -06:00
|
|
|
The `equal` assertion module tests that two items are equal. It has three
|
|
|
|
parameters.
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
* `left` which is required and is the left hand side expression to compare
|
|
|
|
* `right` which is required is the right hand side expression to compare.
|
2019-01-13 22:06:38 -06:00
|
|
|
* `desc` which is an optional description to output for your test. This defaults to
|
|
|
|
a description created from the compared values.
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
```
|
2019-04-09 21:16:19 -05:00
|
|
|
let t = import "std/testing.ucg";
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
assert t.equal{
|
|
|
|
left=1,
|
|
|
|
right=1,
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
### not_equal assertion
|
|
|
|
|
|
|
|
The `not_equal` assertion module tests that two items are not equal. It has two
|
|
|
|
parameters.
|
|
|
|
|
|
|
|
* `left` which is required and is the left hand side expression to compare
|
|
|
|
* `right` which is required is the right hand side expression to compare.
|
2019-01-13 22:06:38 -06:00
|
|
|
* `desc` which is an optional description to output for your test. This defaults to
|
|
|
|
a description created from the compared values.
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
```
|
2019-04-09 21:16:19 -05:00
|
|
|
let t = import "std/testing.ucg";
|
2019-01-13 21:25:15 -06:00
|
|
|
|
|
|
|
assert t.not_equal{
|
|
|
|
left=1,
|
|
|
|
right=2,
|
|
|
|
};
|
|
|
|
```
|