X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fc2171bd4c660b8554dae2a1cbf34ff09f3032a6..7a36d9c7c1a077ba7e05c248bcf19c4c9bb1356f:/docs/tech/tn0017.txt diff --git a/docs/tech/tn0017.txt b/docs/tech/tn0017.txt index 2ba859990c..eeff4c2fee 100644 --- a/docs/tech/tn0017.txt +++ b/docs/tech/tn0017.txt @@ -1,7 +1,7 @@ How to write unit tests for wxWidgets ===================================== - Unit tests for wxWidgets are written using small cppunit framework. To compile +Unit tests for wxWidgets are written using small cppunit framework. To compile (but not to run) them you need to have it installed. Hence the first part of this note explains how to do it while the second one explains how to write the test. @@ -10,14 +10,14 @@ I. CppUnit Installation ----------------------- 1. Get it from http://www.sourceforge.net/projects/cppunit - (latest version as of the time of this writing is 1.8.0) + (latest version as of the time of this writing is 1.10.2) 2. Build the library: - a) Under Windows using VC++ (both versions 6 and 7 work): + a) Under Windows using VC++ (versions 6, 7, 8 & 9 work): - build everything in CppUnitLibraries.dsw work space - add include and lib subdirectories of the directory where you installed cppunit to the compiler search path - using "Tools|Options" menu in VC IDEA + using "Tools|Options" menu in VC IDE b) Under Unix: run configure && make && make install as usual @@ -38,12 +38,33 @@ II. Writing tests with CppUnit // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION(MBConvTestCase); - // also include in it's own registry so that these tests can be run alone + // also include in its own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MBConvTestCase, "MBConvTestCase"); - Read CppUnit documentation for more. - -3. add a '' tag for your source file to tests/test.bkl + Read CppUnit documentation for more. + d) wxUIActionSimulator can be used when user input is required, for example + clicking buttons or typing text. A simple example of this can be found + in controls/buttontest.cpp. After simulating some user input always + wxYield to allow event processing. When writing a test using + wxUIActionSimulator always add the test using WXUISIM_TEST rather than + CPPUNIT_TEST as then it won't run on unsupported platforms. The test itself + must also be wrapped in a #if wxUSE_UIACTIONSIMULATOR block. + e) There are a number of classes that are available to help with testing GUI + elements. Firstly throughout the test run there is a frame of type + wxTestableFrame that you can access through wxTheApp->GetTopWindow(). This + class adds two new functions, GetEventCount, which takes an optional + wxEventType. It then returns the number of events of that type that it has + received since the last call. Passing nothing returns the total number of + event received since the last call. Also there is OnEvent, which counts the + events based on type that are passed to it. To make it easy to count events + there is also a new class called EventCounter which takes a window and event + type and connects the window to the top level wxTestableFrame with the specific + event type. It disconnects again once it is out of scope. It simply reduces + the amount of typing required to count events. + +3. add a '' tag for your source file to tests/test.bkl. Make sure it's + in the correct section: the one starting '