CrayonUnit
Unit testing library.
- namespace CrayonUnit
function assertThat(actualValue)[link]
Used to begin an assertion statement. e.g. assertThat(someValue).isTrue(); Can only be used within the context of a running test class.
Arguments
Name | Type | Description |
---|---|---|
actualValue | object | The actual value of an assertion construct. |
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | Returns a VerificationContextObject, which has methods to perform various assertions on in a readable fashion. |
function fail(message)[link]
Makes the current test a failure.
Arguments
Name | Type | Description |
---|---|---|
message | string | Message to display in the failure. |
function pass()[link]
Virtually does nothing. Increments the assertion counter and makes it clear in the unit test code that the test has performed admirably.
class Test[link]
An abstract base class for a test class.
function setup()[link]
Does nothing by default. Override this to perform any setup necessary for the test methods.
function teardown()[link]
Does nothing by default. Override this to perform any cleanup necessary for the test methods.
class TestHarness[link]
An instance of a test run. Typical usage looks like this: new TestHarness().makePassingTestsSilent().run().showSummary()
new TestHarness()[link]
The constructor takes no arguments.
function makePassingTestsSilent()[link]
When called, this will configure the test harness to not display when a test passes on STDOUT. Failing tests will still show, though.
function run()[link]
Runs all the tests in your project. Tests are gathered by Reflection which looks for any classes that extend from CrayonUnit.Test.
function showSummary()[link]
Displays a summary of results of the test run.
class UnitTestFailedException[link]
An exception thrown when a unit test has failed. Direct construction should be avoided and fail() or an assertion should be used instead.
class VerificationContextObject[link]
An object that contains wraps an actual value that is a result of a test and contains several verification methods that can be used to assert that value. When any of the assertions fail, a UnitTestFailedException is thrown.
function contains(value)[link]
This method is flexible based on the actual and expected value types. If the actual value is a string and the given value is a string, then this checks to see if the string contains the given string. If the actual value is a list and the given value is a list, then this checks to see if the list contains all the values in the given list (but not necessarily in order). To verify that the list matches exactly, you can call .inOrder() after calling contains OR you can use .isEqualTo(expectedValue). If the actual value is a list and the given value is not, it will verify that the expected value is a member of the list.
Arguments
Name | Type | Description |
---|---|---|
value | object | See function description |
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function hasLength(length)[link]
Checks to see if the actual value is a string, list, or dictionary and that its size matches the given length.
Arguments
Name | Type | Description |
---|---|---|
length | integer | The expected length |
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function inOrder()[link]
Once .contains() has been called with a list to verify the contents of the list, this will verify that the contents appear in order.
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function isEmpty()[link]
Checks to see if the actual value is a string, list, or dictionary and that it is empty. Identical to .hasLength(0)
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function isEqualTo(expected)[link]
Verifies that the actual value is identical to the given expected value. Does not use strong reference checks.
Arguments
Name | Type | Description |
---|---|---|
expected | object | The expected value |
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function isEqualWithEpsilon(expected, epsilon)[link]
Checks if the given number matches the expected number, but uses an epsilon value to check floats to make sure the value is close, but not necessary exact. Floating point precision isn't always precise.
Arguments
Name | Type | Optional | Description |
---|---|---|---|
expected | float | The expected numeric value. |
|
epsilon | float | Optional | A tiny value to indicate how much tolerance should be given to differences in the actual value. Default value is 0.000001 |
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function isFalse()[link]
Checks to see if the actual value is the boolean false.
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function isNotEqualTo(value)[link]
Verifies that the actual value is different from the given value.
Arguments
Name | Type | Description |
---|---|---|
value | object | Some value that should not match the actual value. |
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function isNull()[link]
Checks to see if the actual value is null.
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |
function isTrue()[link]
Checks to see if the actual value is the boolean true.
Return Value
Type | Description |
---|---|
CrayonUnit.VerificationContextObject | A reference to itself to allow chaining |