AutomatedTests

From Request Tracker Wiki
Revision as of 02:35, 10 July 2013 by 203.214.145.245 (talk) (Point readers to RT's official docs on testing)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Automated Testing in RT

Please see the official RT documentation for information on running the test suite. This information is incomplete (and outdated; it's "make test" not "make regression").

Introduction

When working with RT (and any large software system) one should really have a large set of automated tests. Best Practical likes patches that come with regression tests, etc etc etc. So write tests.

Basic overview of test framework

The tests are kicked off by make regression this runs a full test suite, which may be more than you want.

Tests all use the Test::More perl module.

Tests from the "old" code are stored in the modules source code, in specific pod sections. They are extracted before being executed.

However, the preferred way of writing tests is now writing test scripts in lib/t/regression/).

Depending on which tests you run, you'll need different amounts of RT installed. Most things should need a working database. Some things will need a webserver.

Tests run smoothly as root, but this may be a problem for some users. Non privileged testing is achievable but your mileage may vary for some parts (tests related to mail gateway and web server).

Details about writing tests

Using Test::More is pretty simple. perldoc Test::More should give you lots of examples, but here's a very simple test:

#!/usr/bin/perl
   
   use strict;
   use warnings;
   use Test::More plan => 2;
   
   is(1, 1, "one should be one");
   isnt(1, 2, "one is not two");
   
   

Writing tests is pretty much just like using the API. You call some whatever you're testing, then you use is or isnt to check that the result is what you expect. I believe 12-search.t should be a pretty clear example.

Tips and tricks

The full regression suite takes a while to run, and depends on lots of things you may not have installed. For example, when hacking on the search related tests, I really didn't want to install enough email pieces to run the email tests. So I made a seph-test target that depended on regression-install regression-reset-db run-regression I also moved most of the tests in lib/t/regression/ aside, so only my test was being run.

The regression tests will use the first perl in your path. So set $PATH appropriately or set $PERL to specify which perl to use.