WebGUI
      Click here to register.
      
PBWG Banner

Developer's Guide to Testing in WebGUI

Running Tests

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

There are basically three ways to run tests:

  1. Via the testCodebase.pl script in sbin
  2. Via prove
  3. One at a time, via perl or prove
Onevery important thing to keep in mind is that the tests may be destructive.  They may rewrite your config file and make permanentchanges in the database.  It is recommended that you NOT run the tests on a production database unless you have a backup.

testCodebase.pl script

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

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

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:

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.

Writing Tests

  1. Please try to write tests so that they follow the directory hierarchy of WebGUI's library directory.
  2. Tests should clean-up after themselves, so that they can be run time and time again without resetting the database.
  3. Just as with core code, please do not rewrite tests wholesale because of style issues.  The goal is to cover as much of WebGUI as possible and make our lives as devs easier.

Keywords: api testing