Debian Codegraph @

doc/Developers/testplans

raw
1 Unit tests and functional tests documentation.
2
3 Crossfire uses the 'check' C automated testing framework available at
4 http://check.sourceforge.net
5 The presence of this framework at compile time is not required but is STRONGLY
6 recommended for developpers. You should not commit changes to the CVS if they
7 are not unit tested. In fact you should even write your new test before writing
8 the change.
9
10 Organization
11 ============
12
13 All automated tests are in subfolders of the test directory. Directory
14 structure is as follow:
15
16 test
17 +-rsc ** contains all runtime ressources unit tests might need (maps, etc)
18 +-include ** include files specific to unit tests
19 +-toolkit ** generic function and toolkit shared by several tests
20 +-unit ** contains all unit tests separated with same structure as tested code
21 | +-headers
22 | +-common
23 | +-socket
24 | +-random_maps
25 | +-server
26 +-bugs ** contains test of known bugs (fixed and opened)
27 | +-bugtrack ** Each file has the number of associated sourceforge bug id
28 | | +-bug_<id>.c
29 | +-unrelated ** Bugs that for a reason or another were not referenced on sf
30 +-functional ** contains all functional tests with structure of tested code
31 | +-common
32 | +-socket
33 | +-random_maps
34 | +-server
35 | +-general ** put here func test not in previous func categories
36 +-plugins
37 //structure still to be defined
38
39 All source file having tests in them should be named test_*.c
40
41 Unit Test
42 =========
43 Put in subfolders of test/unit, They test the various crossfire functions. You
44 must write exactly one test_xxx.c for each xxx.c in crossfire sourcecode. You
45 must test in this test_xxx each function available in xxx.c. If you add a
46 function to xxx.c, write a testcase in test_xxx.c
47 Do no put files other than the test_xyz.c where xyz.c is a crossfire
48 source file. If you need to write test that does not conform to this, this mean
49 they are not unit tests and should go to functional/*
50
51 when test/unit is complete, each function of crossfire will be tested at least
52 once.
53
54 Note: because crossfire makeis heavy use of macros, macros must be considered as
55 function and so must be unit tested too. Because macros are defined in .h file,
56 the unit test should have the form test_xxx for testing xxx.h. All unit tests
57 for .h files go to test/headers
58
59 Functional Test
60 ===============
61 While unit tests are testing each function of the code, functionnal tests are
62 testing behaviour of the whole. They can test behaviour of server after a
63 specific series of actions and check the integration of various modules. So
64 they are not tied to specific .c file or specific function. However, most
65 testcases will be concerned by specific module, so try to put the in
66 corresponding test/function/<module> folder. If that's not possible, put them
67 in test/functional/general.
68
69 Bugs
70 ====
71 When a bug is discovered, here is the procedure to follow:
72 1) write a testcase reproducing it (either in test/bugtrack or in
73 test/unrelated, depending upon the bug being reported on sf or not)
74 2) if the bug was not reported on sourceforge, provide enough information in
75 testcase comments to describe the bug, preferrably at the top of test
76 file, after the GPL licence header.
77 3) when you successfully wrote a failing testcase demonstrating the bug, start
78 to fix it (by writing the test you probably got a good idea of what goes
79 wrong and the automated test will test each fix attempt for you)
80 4) provide short information in test source code on what was wrong. If a later
81 change in crossfire revive the bug, it will help fix it quickly.
82 5) Commit your fix along with test.
83 6) If bug was reported on sourceforge, mark it closed or ask an admin to
84 close it. Mention you wrote a testcase for the bug.
85
86 Test ressources
87 ===============
88 Some test requires maps, archetype or other kind of ressources to run. Those
89 are all provided in rsc or a subdirectory of it. Try to name those files
90 explicitly. Do not name it things like test-map or alike. Prefer forms like
91 rsc/maps/walls_blocks_move or like rsc/arch/selection_of_magic_books
92 each file in src/* should be documented in rsc/index.txt so other coders can
93 reuse those resources. Each subdirectory of rsc should have its own index file.
94
95 Toolkits
96 ========
97 For some testcases (especially the functionnal one), you may need to have a
98 specific crossfire configuration loaded, or to do specific map operation. It
99 won't be surprising some of those operation are generic enough to be shared
100 amongst all testcases. Such support function (aka toolkits) will be made
101 available in the toolkit directory.
102
103 Includes
104 ========
105 Testcases will share some include files not present in crossfire core. Those
106 test specific headers will be put in includes
107
108
109 How to add a subdirectory to test/
110 ==================================
111 Directory to create is assumed to be "bugs/bugtrack"
112
113 Steps:
114 * edit test/Makefile.am, add in the SUBDIR line "bugs"
115 * copy eg unit/Makefile.am to bugs/Makefile.am
116 * edit this file:
117 * change the values for CHECK_FOLDER to bugs (will then read "CHECK_FOLDER=bugs")
118 * change the SUBDIRS line to "bugtrack"
119 * copy eg unit/server/Makefile.am to bugs/bugtrack/Makefile.am
120 * edit this file:
121 * change the TESTS line to add your files
122 * change CHECK_FOLDER to bugs/bugtrack
123 * change CHECK_PARENT_NAME to Bugs
124 * in server root, edit configure.ac to add to Makefile output test/bugs/Makefile and
125 test/bugs/bugtrack/Makefile
126 * in server root, run "sh autogen.sh" to regenerate the Makefiles
127
128 Your new test should be ready to run.