]> git.saurik.com Git - wxWidgets.git/blob - docs/tech/tn0017.txt
added wxTE_AUTO_SCROLL and wxTE_NO_VSCROLL
[wxWidgets.git] / docs / tech / tn0017.txt
1 How to write unit tests for wxWindows
2 =====================================
3
4 Unit tests for wxWindows are written using small cppunit framework. To compile
5 (but not to run) them you need to have it installed. Hence the first part of
6 this note explains how to do it while the second one explains how to write the
7 test.
8
9 I. CppUnit Installation
10 -----------------------
11
12 1. Get it from http://www.sourceforge.net/projects/cppunit
13 (latest version as of the time of this writing is 1.8.0)
14
15 2. Build the library:
16 a) Under Windows using VC++ (both versions 6 and 7 work):
17 - build everything in CppUnitLibraries.dsw work space
18 - add include and lib subdirectories of the directory
19 where you installed cppunit to the compiler search path
20 using "Tools|Options" menu in VC IDEA
21
22 b) Under Unix: run configure && make && make install as usual
23
24
25 II. Writing tests with CppUnit
26 ------------------------------
27
28 1. Create a new directory tests/foo
29
30 2. Write a cpp file for the test copying, if you want,
31 from one of the existing tests. The things to look for:
32 a) #include "wx/cppunit.h" instead of directly including CppUnit headers
33 b) don't put too many things in one test case nor in one method of a test
34 case as it makes understanding what exactly failed harder later
35 c) 'register' your tests as follows so that the test program will find and
36 execute them:
37
38 // register in the unnamed registry so that these tests are run by default
39 CPPUNIT_TEST_SUITE_REGISTRATION(MBConvTestCase);
40
41 // also include in it's own registry so that these tests can be run alone
42 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MBConvTestCase, "MBConvTestCase");
43
44 Read CppUnit documentation for more.
45
46 3. add a '<sources>' tag for your source file to tests/test.bkl
47
48
49 III. Running the tests
50 ----------------------
51
52 1. Regenerate the make/project files from test.bkl using bakefile_gen, e.g.:
53 cd build/bakefile
54 bakefile_gen ../../tests/test.bkl
55 and if you're on a unix system re-run configure.
56
57 2. Build the test program using one of the make/project files in the tests
58 subdirectory.
59
60 3. Run the test program with no arguments to run the default set of tests
61 (which are all those registered with CPPUNIT_TEST_SUITE_REGISTRATION).
62 Or to list the tests without running them:
63 test -l
64
65 4. Tests that have been registered under a name using
66 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION can also be run separately. For
67 example:
68 test MBConvTestCase
69 or to list the tests:
70 test -l MBConvTestCase
71
72
73 IV. Notes
74 ---------
75
76 1. You can register your tests (or a subset of them) just under a name, and not
77 in the unnamed registry if you don't want them to be executed by default.
78
79 2. If you are going to register your tests both in the unnamed registry and
80 under a name, then use the name that the tests have in the 'test -l'
81 listing (which is often the name of the TestCase class). Then the top
82 level names in a 'test -l' listing can be a hint as to the name those
83 tests have been registered under.
84
85
86 === EOF ===
87
88 Author: VZ
89 Version: $Id$