1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/** \page Testcases Writing and tunning testcases
\section Introduction Introduction
ZYpp has a suite of tests located in under test/ directory of the source tree.
Right now, tests are grouped into
- media : tests related to downloading and the http/ftp/nfs/iso abstraction layer
- parser : tests related to classes that offer file format parsing
- repo : tests related to repository handling
- sat : tests related to the sat-solver integration
- zypp : tests related to the main libzypp classes and APIs
Tests are written using boost test library.
- <a href="http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/index.html">Boost Test Library</a>
- <a href="http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/utf.html">The Unit Test Framework</a>
- <a href="http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/utf/testing-tools/reference.html">The UTF testing tools reference</a>
\section Anatomy Anatomy of a ZYpp testcase
The file should be in one of the described groups, and by general rule it is named ClassName_test.cc where ClassName is the name of the class or module the test covers.
Data and fixtures are stored in data/ directories in each test group. However groups may use and reference data from other test groups. The macro \ref TESTS_SRC_DIR is defined as the tests/ directory located in libzypp source directory. You can build the paths to the data/fixtures using that macro.
A simple testcase:
\code
#include "zypp/Date.h"
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE(date_test)
{
std::string format = "%Y-%m-%d %H:%M:%S";
std::string date = "2009-02-14 00:31:30";
BOOST_CHECK_EQUAL(zypp::Date(date,format).form(format), date);
}
\endcode
\section Building Building and running the testsuite
- Build the testsuite
\verbatim
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/prefix ..
$ cd tests
$ make
\endverbatim
- Run a simple test
\verbatim
$ zypp/Date_test
Running 1 test case...
*** No errors detected
\endverbatim
- Run all tests
\verbatim
$ ctest .
\endverbatim
\section
\verbatim
- added tests/data/openSUSE-11.1 containing raw susetags metadata.
Keeping .solv files in svn is somewhat inconvenient, as you must rebuild them
if something in libsolv changes.
\endverbatim
\verbatim
- added tests/include as location for includes that might be used in multiple
testcases.
\endverbatim
\verbatim
- added tests/include/TestSetup.h to ease building a test environment below
some tempdir. Currently supports easy setup of Target, RepoManager and
loading data (raw metadata and .solv files) into the pool.
That's how it currently looks like:
#include "TestSetup.h"
BOOST_AUTO_TEST_CASE(WhatProvides)
{
TestSetup test( Arch_x86_64 ); // use x86_64 as system arch
test.loadTarget(); // initialize and load target
test.loadRepo( TESTS_SRC_DIR"/data/openSUSE-11.1" );
This is all you need to setup Target, RepoManager below some temp directory
and load the raw metadata into the pool.
In case you want to setup the system below some fix directory, use:
TestSetup test( "/tmp/mydir", Arch_x86_64 );
You directory is used as it is and not removed at the end.
\endverbatim
\verbatim
- Added support for loading helix files e.g. from testcases. This is what
you need to load all repos from a solver testcase into the pool:
#include "TestSetup.h"
BOOST_AUTO_TEST_CASE(test)
{
TestSetup test( Arch_x86_64 );
test.loadTestcaseRepos( "/suse/ma/BUGS/153548/YaST2/solverTestcase" );
\endverbatim
\section References
*/
|