2005/5/10

     
 

ACDK Unit test framework

artefaktur

ACDK Unit Test (acdk_tools_aunit) is a library to create regression tests for acdk classes. It is inspired by the Xtrem Programming tool from Kent Beck.


Content of this chapter:

   Write a Test
     The main()
     A Class Test case
   Run the tests
     HTML reports
     More options
   Using CfgScript as Unit Tests
     API documentation
   GUI Test Runner



 Write a Test

The idea for unit tests is to write an executable for a unit, which make a self test for each class in this unit. A unit is mostly identical to the collection of classes of a C++ namespace.

In ACDK projects tests can be found in the ./tests directory.


 The main()



//begin our_unit_Test.cpp
#include <acdk/tools/aunit/TestRunner.h>
#include <acdk/lang/System.h>

ACDK_TEST_MAIN

//end our_unit_Test.cpp


 A Class Test case

For each class in the unit create a .cpp file, which contains the tests for this class.


// begin our_unit_FirstClass.cpp
#include <acdk/tools/aunit/TestRunner.h>
#include <your/unit/FirstClass.h>

namespace tests {
namespace our {
namespace unit {
  
BEGIN_DECLARE_TEST( FirstClass_Test )
  DECLARE_TEST( constructors )
  DECLARE_TEST( method1 )
  // more tests here
END_DECLARE_TEST( FirstClass_Test  )

BEGIN_DEFINE_TEST( FirstClass_Test )
  ADD_TEST( FirstClass_Test, constructors ) 
  ADD_TEST( FirstClass_Test, method1  ) 
  // more tests here
END_DEFINE_TEST( FirstClass_Test )

using namespace acdk::lang;
using namespace your::unit;

void FirstClass_Test::constructors()
{
  RFirstClass fc = new FirstClass();
  testAssert(fc != Nil);
  testAssert(fc->isOk());
  //etc.
}


void FirstClass_Test::method1  ()
{
  int expectedVal = 42;
  RFirstClass fc = new FirstClass();
  testAssert(fc->method1() == expectedVal);
}

} // namespace unit 
} // namespace our 
} // namespace tests 
  

// end our_unit_FirstClass.cpp

 Run the tests

A test executable normally should run without arguments and exit with 0 if all tests succeeded.

./our_unit_Test

For debugging reasons it may usefull to start a single test.

# test the class FirstClass
./our_unit_Test FirstClass_Test 

# test only method FirstClass_Test.method1
./our_unit_Test FirstClass_Test.method1

To list all available tests in a executable you can type:

./our_unit_Test -test-list

 HTML reports

If you start a unit test with the option -test-htmlreport HTML report pages are generated for the test in $ACDKHOME/testreports.

 More options

Run your test executable with the option -help to receive all available options.

 Using CfgScript as Unit Tests

ACDK C++ libraries, which includes Metainfo, may also be tested via CfgScript files.
Insert this into a CPP for the test driver:

// C++
using namespace acdk::tools::aunit;
TestRunnerStaticAdder scriptTests(new CfgScriptTestSuite("$(ACDKHOME)/acdk_sql_sqlite/cfg/csf/tests/acdk/sql/sqlite", true));
will execute all CfgScript in the directory $(ACDKHOME)/acdk_sql_sqlite/cfg/csf/tests/acdk/sql/sqlite (and subdirectories) which ends with _Test.csf as unit test.

 API documentation


Please refer also to  API documentation.

 GUI Test Runner

To run ACDK Unit test, there is also a GUI runner avaible.
To run the AcdkTestRunner you have also to compile the  ACDK WX module.
Then type:
acdkcfgscript[_d.exe|_r.exe] acdk_core/cfg/csf/lib/test/AcdkTestRunner.csf.


GUI to run ACDK Unit Tests


This application is written with  CfgScript and  ACDK WX.