tuitest.rb

Path: swig/lib/tuitest.rb
Last Update: Mon Oct 06 22:52:47 +0200 2008

tuitest.rb - Text User Interface Testing Library

Copyright 2008 Andreas Krennmair ak@synflood.at

Introduction

tuitest is a tool to create and run automated tests of text user interfaces. It is meant as a complement to the widespread use of unit tests, and uses concepts known from GUI testing tools with the difference that it applies them specifically to text- and terminal-based user interfaces.

tuitest consists of two parts: first, the recorder, named tt-record. With the recorder, you start your application under test (AUT) in a fixed 80x25-sized virtual terminal, do the operations you want to have tested, and exit the application. tt-record will generate a script that replays your interaction with the application.

The second part of tuitest is a Ruby module that provides helper functions and classes for the actual replay. The script generated by tt-record is a Ruby script that relies on this Ruby module. All you need to do in order to replay your interaction is to run the script with a Ruby interpreter.

Usage

You create a new script by running

 tt-record scriptname.rb '<commandline>'

Your AUT will then open, and you can simply start interacting with it, doing the operations that you want to have replayed later on. When you‘re finished, quit your AUT, and tt-record will exit. Your script is now ready.

To replay the script, simply run

 ruby scriptname.rb

and you will again see the AUT window come up, your application start, and your AUT will be used in the same way and with exactly the same timing as you did. A snippet of such a script looks like this:

 Tuitest.keypress("r"[0])
 Tuitest.wait(1244)

 Tuitest.keypress(258)
 Tuitest.wait(473)

 Tuitest.keypress("r"[0])
 Tuitest.wait(3453)

 Tuitest.keypress(259)
 Tuitest.wait(2215)

 Tuitest.keypress(10)
 Tuitest.wait(5702)

 Tuitest.keypress("A"[0])
 Tuitest.wait(980)

Adding Verifications

To verify that your AUT behaves correctly, it is necessary to compare the AUT‘s actual output with some expected output. tuitest provides a Verifier class for this (every generated script already contains an instance of it). You can either add your verifications after script recording manually, or you can have the automatically generated during recording.

The automatic generation of verifications works this way: at a certain point in time during execution, you take a snapshot of your AUT‘s current state, by pressing the F5 key. Subsequently pressing F5 will overwrite the previous snapshot. When you want to automatically generate verifications, press the F6 key. This will take another snapshot, but this time, all differences between the last snapshot taken with F5 and the current snapshot taken with F6 will be inserted as verifications into the script. This is especially useful when you press F5, then execute a certain action that leads to changes on the screen, and then press F6 to generate verifications for these changes.

After pressing F6, the snapshot used for verification generation will be the latest one.

Here is an example of how an auto-generated verification looks like:

 # begin auto-generated verification #1
 verifier.expect(0, 65, "0 unread, 10 to")
 verifier.expect(1, 5, " ")
 verifier.expect(2, 5, " ")
 verifier.expect(3, 5, " ")
 verifier.expect(4, 5, " ")
 # end auto-generated verification #1

After having the script recorded, it is recommended to edit the script and to only use those verifications that are relevant to the test case.

Making Scripts Faster

When running tests, one often doesn‘t want to have a very accurate timing, but wants to have the tests executed as quickly as possible. In order to improve the speed of executions, the following "recipe" can be used: Remove all the Tuitest.wait calls from your script. Insert a

 Tuitest.wait_until_idle

call right after the Tuitest.run call, and before every block of verifications. Tuitest.wait_until_idle stops execution until there is no screen change for more than 1 second. This is useful to give the AUT time to "catch up" with all the input that it gets.

To automatically generate such scripts during recording, use tt-record with the -f parameter. This will generate fast scripts.

Integration with Test Management Tools

If you want to integrate tuitest with test management tools, you can specify an (optional) XML file that contains the test run results. The format of this XML file is the same as produced by JUnit. These test run results can thus be used by your favorite test result reporting tool. The integration has been tested with the CI tool Hudson.

Required files

tuitest.so  

[Validate]