plainblack.com
Username Password
search
Bookmark and Share
Subscribe

Developer's Guide to Testing in WebGUI

Running Tests

All tests live in the t/ directory, /data/WebGUI/t.

Tests do not need to be run as root, but the user who runs the tests must meet these conditions:

  • Must be able to read and write the WebGUI configuration file for the tests.
  • Must be able to write to the WebGUI core files.
  • Must be able to write to the WebGUI log file.
  • Must be able to write to the uploads area defined in the configuration file.

There are basically three ways to run tests:

  1. Via the testCodebase.pl script in /data/WebGUI/sbin
  2. Via prove
  3. One at a time, via perl or prove

One very important thing to keep in mind is that the tests may be destructive.  They may rewrite your config file and make permanent changes in the database.  It is recommended that you NOT run the tests on a production database unless you have a backup.

testCodebase.pl script

The testCodebase.pl script in sbin is a wrapper around prove, and it is the easiest way to run the entire test suite.  testCodebase.pl needs to be executed from within the directory /data/WebGUI/sbin.

The script handles setting up environment variables needed to run various sections of the test. You need to give it a valid WebGUI config file that points to a scratch database.  Run the script with the -h switch to get a summary of the options.

Run all tests, including i18n label validation and code inline help:

perl testCodebase.pl --configFile www.example.com.conf

Run all tests, skipping the long tests:

perl testCodebase.pl --configFile --noLongTests www.example.com.conf 

Running tests via prove

If you just want to run one or two sections (directories) of tests, you want to use prove.  Just as with running testCodebase.pl, you need a valid WebGUI config file that points to a scratch database.

  1. Using the correct syntax for your shell, set the WEBGUI_CONFIG variable to the absolute path to your config file:
    • export WEBGUI_CONFIG=/data/WebGUI/etc/testing.conf
  2. Run prove with the -r switch to recurse through all tests in a directory
    • prove -r dir1 dir2
  3. Run prove directly on a test:
    • prove test.t
  4. Run prove directly on a test with verbose output:
    • prove -v test.t

Running tests via perl

Tests are just perl scripts, so you can run them from the command line: (make sure you are using a valid WebGUI config file that oints to a scratch database)

perl test.t or
env WEBGUI_CONFIG=/data/WebGUI/etc/notAProductionSite.conf perl test.t

Test Output

The main WebGUI test module t/lib/WebGUI/Test.pm, sets up the tests so that STDERR is redirected to STDOUT.  This is for convenience.

WebGUI::Test also redirects logfile output so that it can be tested and verified, so do not look in your webgui.log file for errors.  You can either poke down into the errorHandler guts, or use the variables setup inside of WebGUI::Test.  See t/Session/ErrorHandler.t for examples.

Using WebGUI::PseudoRequest to submit request data

If your test needs to pass data to WebGUI via a web request (e.g., you need to submit data via parameters), then you can use the PseudoRequest library in t/lib/WebGUI. There is no documentation besides reading the code. Check out the t/Session/Http.t for examples of use.

see also Writing Tests

Keywords: api Development testing

Search | Most Popular | Recent Changes | Wiki Home
© 2023 Plain Black Corporation | All Rights Reserved