Bonjour,
Je me suis amusé à me créer mon propre logiciel de test unitaire, qui me semble assez simple à utiliser :
Pour le lancer actuellement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233 TEST_FILE_D(Assertions) TEST_FILE_D(Exceptions) TEST_SERIE_D(Assertions, success) { INIT_FUNCTION { std::cout << "Begin serie" << std::endl; }; BEFORE_FUNCTION { std::cout << "Begin test" << std::endl; }; AFTER_FUNCTION { std::cout << "Test finished" << std::endl; }; DESTROY_FUNCTION { std::cout << "Serie finished" << std::endl; }; TEST(success) { SUCCESS; // quit }; TEST(success_continue) { int * i = new int(2); C_SUCCESS; // continue delete i; }; TEST(success_on) { int i = 3; SUCCESS_ON(i == 3); // quit with success if true FAIL("ERROR"); }; TEST(success_continue_on) { int * i = new int(2); C_SUCCESS_ON(*i == 3) // continue else C_FAIL("ERROR"); delete i; // we can free this ressource }; TEST(empty) // = SUCCESS { }; }; END_SERIE TEST_SERIE_D(Assertions, failure) { int i = 5; // you can declare variables TEST(failure) { FAIL("Because"); // quit }; TEST(failure_continue) { int * i = new int(2); C_FAIL("Because"); // continue delete i; }; TEST(failure_on) { FAIL_ON(i == 5, "Error"); // quit with error if true }; TEST(failure_continue_on) { int * i = new int(2); C_FAIL_ON(*i == 3, "Error") // continue else C_SUCCESS; delete i; // we can free this ressource }; }; END_SERIE TEST_SERIE_D(Assertions, warning) { int i; // you can declare variables INIT_FUNCTION { i = 5; // and used here; }; TEST(warning) { WARNING("Because"); // quit }; TEST(warning_continue) { int * i = new int(2); C_WARNING("Because"); // continue delete i; }; TEST(warning_on) { WARNING_ON(i == 5, "lu"); // quit with warning if true }; TEST(warning_continue_on) { int * i = new int(2); C_WARNING_ON(*i == 3, "warnin") // continue else C_SUCCESS; delete i; // we can free this ressource }; }; END_SERIE TEST_SERIE_D(Assertions, alea) { int tab[4][2][1]; REPEATABLE_TEST(alea) VAR(i, tab) // for each i in tab VAR(j, i) // and for each j in i VAR(k, j) // and for each k in j START_REPEATABLE_TEST { ALEA(k, "Error"); // Error with the value k } END_REPEATABLE_TEST REPEATABLE_TEST(alea_continue) VAR(i, tab) // for each i in tab VAR(j, i) // and for each j in i VAR(k, j) // and for each k in j START_REPEATABLE_TEST { int * i = new int; C_ALEA( (std::size_t)j, "Error"); // Error with the value j delete i; } END_REPEATABLE_TEST REPEATABLE_TEST(alea_on) VAR(i, tab) // for each i in tab VAR(j, i) // and for each j in i VAR(k, j) // and for each k in j START_REPEATABLE_TEST { ALEA_ON(k, k == 0, "Error"); // Error with the value k } END_REPEATABLE_TEST REPEATABLE_TEST(alea_continue_on) VAR(i, tab) // for each i in tab VAR(j, i) // and for each j in i VAR(k, j) // and for each k in j START_REPEATABLE_TEST { int * i = new int; C_ALEA_ON( (std::size_t)i, k == 0, "Error"); // Error with the value i delete i; } END_REPEATABLE_TEST }; END_SERIE TEST_SERIE_D(Exceptions, no_policy ) { TEST( throws ) { throw int(1); }; TEST( throws_with ) { FAIL_ON_CATCH("Erreur !!!"); throw int(2); }; TEST( nothrow ) { }; }; END_SERIE TEST_SERIE_D(Exceptions, policy) { POLICY_WARNING_ON_CATCH("Exception uncaught"); TEST( throws ) { throw int(3); }; TEST( throws_with ) { FAIL_ON_CATCH("Erreur !!!"); throw int(4); }; TEST( throws_with2 ) { SUCCESS_ON_CATCH("Erreur !!!"); throw int(5); }; }; END_SERIE
Et voici l'affichage des résultats :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 int main(void) { LT::UnitTestsManager testManager; // les deux lignes suivantes disparaîtront dans une future version, il chargera les tests comme des bibliothèques dynamique // pour activer/désactiver/échanger des tests sans recompiler. testManager.addUnitTestsFile("Assertions", __LT__TestsFileAssertions() ); testManager.addUnitTestsFile("Exceptions", __LT__TestsFileExceptions() ); testManager.launch(); LT::UnitTestsPrinter printer(testManager); // affiche les résultats return 0; }
Begin serie
Begin test
Test finished
Begin test
Test finished
Begin test
Test finished
Begin test
Test finished
Begin test
Test finished
Serie finished
#####################
########## BEGIN TEST
#####################
=======================
====== 1/2 Assertions
=======================
======
== 1/4 success
======
1/5 [O] success :
2/5 [O] success_continue :
3/5 [O] success_on :
4/5 [X] success_continue_on : ERROR
5/5 [O] empty :
======
== Resume
======
4/5 [X] success_continue_on : ERROR
======
== X:1 A:0 W:0 on 5 tests
======
======
== 2/4 failure
======
1/4 [X] failure : Because
2/4 [X] failure_continue : Because
3/4 [X] failure_on : Error
4/4 [O] failure_continue_on :
======
== Resume
======
1/4 [X] failure : Because
2/4 [X] failure_continue : Because
3/4 [X] failure_on : Error
======
== X:3 A:0 W:0 on 4 tests
======
======
== 3/4 warning
======
1/4 [W] warning : Because
2/4 [W] warning_continue : Because
3/4 [W] warning_on : lu
4/4 [O] warning_continue_on :
======
== Resume
======
1/4 [W] warning : Because
2/4 [W] warning_continue : Because
3/4 [W] warning_on : lu
======
== X:0 A:0 W:3 on 4 tests
======
======
== 4/4 alea
======
1/4 [A] alea : Error
2/4 [A] alea_continue : Error
3/4 [A] alea_on : Error
4/4 [A] alea_continue_on : Error
======
== Resume
======
1/4 [A] alea : Error
2/4 [A] alea_continue : Error
3/4 [A] alea_on : Error
4/4 [A] alea_continue_on : Error
======
== X:0 A:4 W:0 on 4 tests
======
=======================
====== Resume tests
=======================
4/5 of 1/4 [X] success_continue_on/success : ERROR
1/4 of 2/4 [X] failure/failure : Because
2/4 of 2/4 [X] failure_continue/failure : Because
3/4 of 2/4 [X] failure_on/failure : Error
1/4 of 4/4 [A] alea/alea : Error
2/4 of 4/4 [A] alea_continue/alea : Error
3/4 of 4/4 [A] alea_on/alea : Error
4/4 of 4/4 [A] alea_continue_on/alea : Error
1/4 of 3/4 [W] warning/warning : Because
2/4 of 3/4 [W] warning_continue/warning : Because
3/4 of 3/4 [W] warning_on/warning : lu
======================
====== X:4 A:4 W:3 on 17 tests
======================
====== Resume Series
======================
1/4 [X] success X:1 A:0 W:0
2/4 [X] failure X:3 A:0 W:0
4/4 [A] alea X:0 A:4 W:0
3/4 [W] warning X:0 A:0 W:3
======================
====== X:2 A:1 W:1 on 4 series
======================
=======================
====== 2/2 Exceptions
=======================
======
== 1/2 no_policy
======
1/3 [X] throws : Unknown Exception was caught
2/3 [X] throws_with : Erreur !!! (Unknown)
3/3 [O] nothrow :
======
== Resume
======
1/3 [X] throws : Unknown Exception was caught
2/3 [X] throws_with : Erreur !!! (Unknown)
======
== X:2 A:0 W:0 on 3 tests
======
======
== 2/2 policy
======
1/3 [W] throws : Exception uncaught (Unknown)
2/3 [X] throws_with : Erreur !!! (Unknown)
3/3 [O] throws_with2 : (Unknown)
======
== Resume
======
2/3 [X] throws_with : Erreur !!! (Unknown)
1/3 [W] throws : Exception uncaught (Unknown)
======
== X:1 A:0 W:1 on 3 tests
======
=======================
====== Resume tests
=======================
1/3 of 1/2 [X] throws/no_policy : Unknown Exception was caught
2/3 of 1/2 [X] throws_with/no_policy : Erreur !!! (Unknown)
2/3 of 2/2 [X] throws_with/policy : Erreur !!! (Unknown)
1/3 of 2/2 [W] throws/policy : Exception uncaught (Unknown)
======================
====== X:3 A:0 W:1 on 6 tests
======================
====== Resume Series
======================
1/2 [X] no_policy X:2 A:0 W:0
2/2 [X] policy X:1 A:0 W:1
======================
====== X:2 A:0 W:0 on 2 series
======================
#####################
########## RESUME TESTS
#####################
4/5 of 1/4 of 1/2[X] success_continue_on/success/Assertions : ERROR
1/4 of 2/4 of 1/2[X] failure/failure/Assertions : Because
2/4 of 2/4 of 1/2[X] failure_continue/failure/Assertions : Because
3/4 of 2/4 of 1/2[X] failure_on/failure/Assertions : Error
1/3 of 1/2 of 2/2[X] throws/no_policy/Exceptions : Unknown Exception was caught
2/3 of 1/2 of 2/2[X] throws_with/no_policy/Exceptions : Erreur !!! (Unknown)
2/3 of 2/2 of 2/2[X] throws_with/policy/Exceptions : Erreur !!! (Unknown)
1/4 of 4/4 of 1/2[A] alea/alea/Assertions : Error
2/4 of 4/4 of 1/2[A] alea_continue/alea/Assertions : Error
3/4 of 4/4 of 1/2[A] alea_on/alea/Assertions : Error
4/4 of 4/4 of 1/2[A] alea_continue_on/alea/Assertions : Error
1/4 of 3/4 of 1/2[W] warning/warning/Assertions : Because
2/4 of 3/4 of 1/2[W] warning_continue/warning/Assertions : Because
3/4 of 3/4 of 1/2[W] warning_on/warning/Assertions : lu
1/3 of 2/2 of 2/2[W] throws/policy/Exceptions : Exception uncaught (Unknown)
#####################
########## X:7 A:4 W:4 on 23 tests
#####################
########## RESUME SERIES
#####################
1/4 of 1/2[X] success/Assertions X:1 A:0 W:0
2/4 of 1/2[X] failure/Assertions X:3 A:0 W:0
1/2 of 2/2[X] no_policy/Exceptions X:2 A:0 W:0
2/2 of 2/2[X] policy/Exceptions X:1 A:0 W:1
4/4 of 1/2[A] alea/Assertions X:0 A:4 W:0
3/4 of 1/2[W] warning/Assertions X:0 A:0 W:3
#####################
########## X:4 A:1 W:1 on 6 series
#####################
########## RESUME FILES
#####################
1/2 [X] Assertions X:2 A:1 W:1 on 4 series
2/2 [X] Exceptions X:2 A:0 W:0 on 2 series
#####################
########## X:2 A:0 W:0 on 2 FILES
#####################
Qu'en pensez-vous pour le moment ?
Est-ce que cela vous semble intuitif ou trop compliqué ? (Je fais bien exprès de ne pas donner d'informations ^^).
Est-ce que cela vous semble intéressant ? Ou est-ce une horreur comparé à ce qui existe actuellement ?
Avez-vous des idées d'évolutions ? (ex. Je pense chronométrer l'exécution de chaque tests).
Partager