Delirium is a tool for testing PLT web application user interfaces. It allows programmers to write tests with unprecedented clarity and speed. Delirium is built on top of SchemeUnit and the PLT Web Server.
Here is an example test case that tests a login page for a simple web application:
|( "Users can log in via the login page"|
|; The test database starts off empty: we need a new user:|
|( ([user (make-user #:username "dave" #:password "password")]|
|; Save the user to the database:|
|; Open the login page in the browser:|
|; Fill in the login form in the browser:|
|( ( 'username-field) "dave")|
|( ( 'password-field) "password")|
|; Click 'Submit' and wait for the page to refresh:|
|; Check the page title is 'Welcome, dave!'|
|( () "Welcome, dave!")|
|; Check the login was recorded:|
|( (user-last-login user) now)))|
This is a standard SchemeUnit test-case being run inside Delirium. The code used comes from three sources:
Delirium tests are defined on the server, so they have access to all the library code used in the web application being tested. The make-user, save! and user-last-login in the example are all imported from the application itself.
Delirium is built on top of SchemeUnit, which provides a rich testing framework. The , and forms in the example are standard procedures and macros from SchemeUnit.
Note that, like SchemeUnit tests, Delirium tests are all fully fledged Scheme code: you can use all the abstractions that you would expect, including loops, conditionals, procedures and macros.
Delirium only works on web applications created for the PLT Web Server. Applications are set up so they can be run in two different modes:
Production mode bypasses all of the Delirium setup and simply runs the application.
Test mode runs the application with whatever external resources (databases, configuration files, user credentials) are needed for testing, and sets up a special test servlet that runs Delirium.
Here is an example start procedure from a test servlet:
|; start : request -> response|
|( (start request)|
|; run-delirium : request schemeunit-test-suite -> response|
|(run-delirium request my-ui-test-suite))|
The test servlet is typically mapped to a URL like http://localhost:8080/test. When the servlet is invoked, run-delirium will send a test-page to the browser. The test-page contains an <iframe> in which the web application is loaded. All browser API calls like and are directed at the frame. All the test suite has to do is call to load part of the web application and start testing it.
Delirium uses continuations to maintain a REPL-style testing loop:
Tests are run until a browser API call is encountered.
The result of the command is sent back to the server as a block of JSON.
The JSON is converted into a Scheme value, which is returned by the API call.
More tests are run until the next browser API call is encountered...