HTTP tests
HTTP tests are simple JavaScript functions, that are registered to a registry, along with a URL, an HTTP method (e.g. 'GET'), a set of HTTP headers and a body. The test library generates an HTTP request with that data and sends it to the server. When a reponse has been received, the test function will be called with the response as an argument, allowing its body and headers to be examined.
This type of tests allows testing REST-like APIs.
Example
// a simple test function, assumes there's a cgi script called 'square.cgi' in // the root of the proxy which returns 4 if a POST body 'int=16' is inputted, // if this fails, an error is reported and the next test is called function test_square_root(testcase, status, headers, body) { testcase.assertEquals(status, '200'); testcase.assertEquals(headers['content-type'].substr(0, 10), 'text/plain'); // note that string.strip() is a function of the 'jsbase' library testcase.assertEquals(string.strip(body), '4'); }; // register the function so it can be ran later window.httpunit_test_registry.push([ test_square_root, // test function '/square_root.cgi', // url to test 'POST', // method {'Content-Type': 'application/x-www-form-urlencoded'}, // headers 'int=16' // body ]);
