test-tube.HttpTest
extends Test
An extension of Test
that simplifies testing of HTTP based web services. In general, this will be used as a test-suite, as it parses the sub-tests to build test objects that make HTTP requests and validate HTTP responses using a simple specification format. Services that are being tested can be started in a parent test or using setup
. Similarly, services can be stopped in a parent test or using teardown
.
Instance Properties
-
_main |
Object
|
Required |
|
Description |
The entry point for the “run” command” |
-
baseUrl |
string
|
Required |
|
Description |
The base URL for all tests in the test-suite. This will be prepended to any URL specified in the suite. |
-
cmdargs |
Object.<string, Object>
(read-only)
|
Description |
The cmdargs definition describing the command line interface when a test-suite is executed. See the atom documentation for a description of the format and options available. |
-
description |
string
|
Required |
|
Description |
A short description of the test or test-suite used for display purposes |
-
errorExpected |
boolean | Error
|
Default |
false |
Description |
Indicate that an error is expected to be thrown in this test. This can be used as shorthand alternative to using assert.throws . Note, if this is not a boolean, assert.throws will be used to validate the error thrown by the test. |
-
name |
string
|
Required |
|
Description |
Name of the test. This is used for display and filtering purposes. |
-
parent |
(read-only)
|
Description |
A pointer to the “parent” test-suite. This is useful when a test needs to access a fixture created by the parent test-suite. It will be initialized by test-tube when the test tree is initialized. |
-
selfBeforeChildren |
boolean
|
Default |
false |
Description |
A flag to indicate that doTest should be run before executing any tests in tests when an instance of Test acts as both a test and a test-suite (top-down vs. bottom-up execution). |
-
tests |
test-tube.Test[]
|
Required |
|
Description |
A list of tests to execute as part of a test-suite. Note, these tests can themselves be test-suites. |
Methods
-
_buildTestResult |
|
Return type |
TestResult |
Description |
A factory function for test result objects |
-
_checkName |
|
Arguments |
|
Returns |
true if the test name is filtered, false otherwise |
Return type |
boolean |
Description |
Checks if the current test is filtered by name (think basename ) |
-
_checkPath |
|
Arguments |
- context (test-tube.TestContext) – A context object
- useDirname (boolean) – Use
path.dirname to grab the parent of the path retrieved from context
|
Returns |
true if the test path is filtered, false otherwise |
Return type |
boolean |
Description |
Checks if the current path is filtered where “path” is built using the test names as they appear in the depth-first traversal up to the current test being executed (think dirname ) |
-
_errorExpected |
|
Arguments |
- result (Object) – A test result object (see
_buildTestResult )
- error (Error) – An error object as thrown by the test
|
Returns |
An updated test result object |
Return type |
Object |
Description |
Updates test result if an error was expected and encountered |
-
_executeHttpTest |
|
Arguments |
|
Return type |
undefined |
Description |
Runs a test in the test-suite |
-
_generateReportHelper |
|
Arguments |
- result (TestResult) – The result object for this test
- level (number) – The depth of this test in the overall test tree
|
Return type |
undefined |
Description |
Recursively enerates and outputs the report for a test and sub-tests |
-
_generateReportSummary |
|
Arguments |
|
Return type |
undefined |
Description |
The result object for the test-suite |
-
_init |
|
Return type |
undefined |
Description |
Initialize the test object |
-
_initContext |
|
Arguments |
|
Throws |
TypeError Thrown if testContextClass is not TestContext or a subclass thereof |
Returns |
An instance of TestContext |
Return type |
test-tube.TestContext |
Description |
Initializes the TestContext object that will be passed down to every test in the tree |
-
_initTest |
|
Arguments |
- test (TestSpec | test-tube.Test) – undefined
|
Return type |
test-tube.Test |
Description |
The test spec (note, if this is already an instance of Test , it will simply be returned) |
-
_initTests |
|
Return type |
undefined |
Description |
Runs _initTest on each test in tests . Note, this will replace any TestSpec with an instance of Test that implements the spec. |
-
_log |
|
Arguments |
- msg (string) – A message to be logged
- level (number) – The number of spaces to indent the message
|
Return type |
undefined |
Description |
Logs a message to stdout , indenting each line as appropriate |
-
_postrun |
|
Arguments |
|
Return type |
undefined |
Description |
Restores the previous HttpHistory object if one existed |
-
_prerun |
|
Arguments |
|
Return type |
undefined |
Description |
Creates a new HttpHistory object for this test-suite and stashes any previous history object that may be present in order to restore it when this suite finishes execution. |
-
_runSelf |
|
Arguments |
|
Return type |
SelfTestResult |
Description |
Runs doTest and generates a result |
-
generateReport |
|
Arguments |
|
Return type |
undefined |
Description |
The top-level test result object |
-
run |
|
Arguments |
- context (test-tube.TestContext) – A context object
- done (function) – Errback to call when executing asynchronously
|
Return type |
TestResult |
Description |
run description |
-
setup |
|
Arguments |
- context (test-tube.TestContext) – A context object that can be used to pass data between tests or their methods.
- done (function) – Errback to call when executing asynchronously. Note, when implementing a test, if this is not included in the parameter list, the test will be called synchronously and you will not be responsible for calling the errback.
|
Return type |
undefined |
Description |
Setup any fixtures required for doTest or any test in tests |
-
teardown |
|
Arguments |
- context (test-tube.TestContext) – A context object that can be used to pass data between tests or their methods.
- done (function) – Errback to call when executing asynchronously. Note, when implementing a test, if this is not included in the parameter list, the test will be called synchronously and you will not be responsible for calling the errback.
|
Returns |
undefined |
Return type |
undefined |
Description |
Teardown (cleanup) any fixtures that may have been created in setup |
-
toJSON |
|
Return type |
Object |
Description |
Generates a simplified Object representing the test instance suitable for serializing to JSON |
Typedef: ReqSpec
Properties
-
method |
string
|
Required |
|
Description |
The HTTP request method to use (e.g., “GET”, “POST”, “PUT”, etc.) |
-
url |
string
|
Required |
|
Description |
The URL that should be requested. Note, baseUrl will be prepended to this value when making the request. |
-
parameters |
Object
|
Required |
|
Description |
The query string parameters to include in the request URL |
headers |
Object
|
Required |
|
Description |
The headers to include with the request |
-
body |
Object | Array
|
Required |
|
Description |
The body to include with the request |
-
options |
Object
|
Required |
|
Description |
Options that should be passed directly to the underlying “requests” module |
Typedef: ResSpec
Properties
-
statusCode |
number | function
|
Required |
|
Description |
The HTTP status code of the |
headers |
Object | function
|
Required |
|
Description |
The response headers |
-
body |
Object | Array | function
|
Required |
|
Description |
The response body |
Typedef: TestSpec
Properties
-
name |
string
|
Required |
|
Description |
Used to name the test (note, a name will be generated using the method and URL if this is omitted) |
-
description |
string
|
Required |
|
Description |
See description |
-
setup |
function
|
Required |
|
Description |
See setup |
-
teardown |
function
|
Required |
|
Description |
See teardown |
-
reqSpec |
|
Required |
|
Description |
A specification of the request to be sent |
-
resSpec |
|
Required |
|
Description |
A specification of the response expected |