Libzypp/Devel/Dejagnu

From openSUSE

Contents

Dejagnu

Dejagnu is an automated testing framework around expect and Tcl/Tk Tcl/Tk.

There are plenty of resources around Tcl/Tk available. For expect, this book seems to be the major resource.

But don't worry, you don't have to learn expect or tcl/tk for testing your code.

How does it work ?

You run the testsuite either by

make check

at the toplevel or the testsuite directory or by calling runtest in this directory

cd testsuite
runtest

This will look at libzypp.test/ and run any .exp (expect file, coded in tcl/tk syntax) files it finds.

Code common to all tests should be placed in lib/libzypp_init.exp. Dejagnu ensures that this code is executed prior to running a test. See the dejagnu manual for further options.

The current libzypp testsuite defines two functions for running tests. One to ensure success and one to ensure failure.

  • shouldPass prog path

Running prog should result in a passed test.
path is an optional directory path and defaults to tests

  • shouldFail prog path

Running prog should result in a failed test.
path is an optional directory path and defaults to tests

Sample testcase

A sample testcase is testing the Arch class.

It consists of or touches the following parts

  • tests/Arch.cc
  • tests/Makefile.am
  • libzypp.test/Arch.exp

tests/Arch.cc

...
int main( int argc, char * argv[] )
{
Arch        _arch( "i386" );

return 0;
}


tests/Makefile.am

...
noinst_PROGRAMS = Arch
...
Arch_SOURCES = Arch.cc
...

libzypp.test/Arch.exp

shouldPass "Arch"

And that's it for a testcase. You usually don't need more.

Just look at other testcases to get an idea how to construct a test.


Adding a testcase

Adding a testcase is a few simple steps

1. Code the testcase below tests/, e.g. tests/Solver.cc 1. Adapt tests/Makefile.am
Add the name of the file to noinst_PROGRAMS, e.g.

noinst_PROGRAMS = ... Solver

Tell Makefile.am where the source is

Solver_SOURCES = Solver.cc

1. Add it to the testcases below libzypp.test/, e.g libzypp.test/Solver.exp

shouldPass "Solver"


Back

Last edit in Trac '11/22/05 10:13:22' by 'kkaempf'


Last edit in Trac '11/22/05 10:13:22' by 'kkaempf'


Last edit in Trac '11/22/05 10:13:22' by 'kkaempf'


Last edit in Trac '11/22/05 10:13:22' by 'kkaempf'