Unit Test

From AbiWiki

(Difference between revisions)
Jump to: navigation, search
(New page: UnitTest is part of the TestingFramework. It performs basic testing of individual code units.^M ^M ---+++ How to use^M ^M On Unix, simply run^M ^M =make test=^M ^M It will run under Valgri...)
Line 1: Line 1:
-
UnitTest is part of the TestingFramework. It performs basic testing of individual code units.^M
+
UnitTest is part of the TestingFramework. It performs basic testing of individual code units.
-
^M
+
 
-
---+++ How to use^M
+
---+++ How to use
-
^M
+
 
-
On Unix, simply run^M
+
On Unix, simply run
-
^M
+
 
-
=make test=^M
+
=make test=
-
^M
+
 
-
It will run under Valgrind if configure did detect it.^M
+
It will run under Valgrind if configure did detect it.
-
^M
+
 
-
Here is the sample output of a test from a real bug:^M
+
Here is the sample output of a test from a real bug:
-
^M
+
 
-
<verbatim>^M
+
<verbatim>
-
Testing "UT_LocaleTransactor" in ut_locale.t.cpp:^M
+
Testing "UT_LocaleTransactor" in ut_locale.t.cpp:
-
! ut_locale.t.cpp:35    strstr(msg, "1,0") == msg                                      ok^M
+
! ut_locale.t.cpp:35    strstr(msg, "1,0") == msg                                      ok
-
! ut_locale.t.cpp:37    strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0 ok^M
+
! ut_locale.t.cpp:37    strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0 ok
-
! ut_locale.t.cpp:41    NOT(strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0) ok^M
+
! ut_locale.t.cpp:41    NOT(strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0) ok
-
! ut_locale.t.cpp:43    strstr(msg, "1.0") == msg                                      ok^M
+
! ut_locale.t.cpp:43    strstr(msg, "1.0") == msg                                      ok
-
! ut_locale.t.cpp:44    strcmp(setlocale(LC_NUMERIC, NULL), "C") == 0 ok^M
+
! ut_locale.t.cpp:44    strcmp(setlocale(LC_NUMERIC, NULL), "C") == 0 ok
-
! ut_locale.t.cpp:46    strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0 FAILED^M
+
! ut_locale.t.cpp:46    strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0 FAILED
-
! ut_locale.t.cpp:48    strstr(msg, "1,0") == msg                                      FAILED^M
+
! ut_locale.t.cpp:48    strstr(msg, "1,0") == msg                                      FAILED
-
! tf_test.cpp:119      new_valgrind_errs == old_valgrind_errs  ok^M
+
! tf_test.cpp:119      new_valgrind_errs == old_valgrind_errs  ok
-
memleaks: sure:112 dubious:800 reachable:451080 suppress:0^M
+
memleaks: sure:112 dubious:800 reachable:451080 suppress:0
-
! tf_test.cpp:123      new_valgrind_leaks == old_valgrind_leaks ok^M
+
! tf_test.cpp:123      new_valgrind_leaks == old_valgrind_leaks ok
-
</verbatim>^M
+
</verbatim>
-
^M
+
 
-
As you can see, some test pass, some fails.^M
+
As you can see, some test pass, some fails.
-
The last 3 lines are for Valgrind. If they fail, then there is a Valgrind error in the code: a memory leak.^M
+
The last 3 lines are for Valgrind. If they fail, then there is a Valgrind error in the code: a memory leak.
-
^M
+
 
-
---+++ How to write some^M
+
---+++ How to write some
-
^M
+
 
-
Writing UnitTest is not really hard, if you understand the code. Sometime it is tricky because some classes are not meant to be used alone. ^M
+
Writing UnitTest is not really hard, if you understand the code. Sometime it is tricky because some classes are not meant to be used alone.  
-
^M
+
 
-
---++++ Directory structure^M
+
---++++ Directory structure
-
^M
+
 
-
Every directory that contains code has a =t= directory the contains its test.^M
+
Every directory that contains code has a =t= directory the contains its test.
-
^M
+
 
-
The support code for the UnitTest is in =abi/src/af/tf/xp/=.^M
+
The support code for the UnitTest is in =abi/src/af/tf/xp/=.
-
^M
+
 
-
The files are organized to match the source code files. They have the same name but with the =.t.cpp= suffix. (=.t.mm= for Objective-C++ file where applicable).^M
+
The files are organized to match the source code files. They have the same name but with the =.t.cpp= suffix. (=.t.mm= for Objective-C++ file where applicable).
-
^M
+
 
-
---++++ One test^M
+
---++++ One test
-
^M
+
 
-
Here is a sample test for =UT_Vector=:^M
+
Here is a sample test for =UT_Vector=:
-
^M
+
 
-
<verbatim>^M
+
<verbatim>
-
TFTEST_MAIN("UT_GenericVector basics")^M
+
TFTEST_MAIN("UT_GenericVector basics")
-
{^M
+
{
-
                   UT_GenericVector<char *> v;^M
+
                   UT_GenericVector<char *> v;
-
^M
+
 
-
                   TFPASS(v.getItemCount() == 0);^M
+
                   TFPASS(v.getItemCount() == 0);
-
                   v.addItem("foo");^M
+
                   v.addItem("foo");
-
                   TFFAIL(v.getItemCount() == 0);^M
+
                   TFFAIL(v.getItemCount() == 0);
-
}^M
+
}
-
</verbatim>^M
+
</verbatim>
-
^M
+
 
-
=TFTEST_MAIN= is a macro to declare the test function.^M
+
=TFTEST_MAIN= is a macro to declare the test function.
-
^M
+
 
-
=TFPASS()= is a macro to check some condition that should be true^M
+
=TFPASS()= is a macro to check some condition that should be true
-
^M
+
 
-
=TFFAIL()= is a macro to check a condition that should be false^M
+
=TFFAIL()= is a macro to check a condition that should be false
-
^M
+
 
-
---++++ Makefile^M
+
---++++ Makefile
-
^M
+
 
-
TBD^M
+
TBD
[[Category:To Convert]]
[[Category:To Convert]]

Revision as of 19:42, 12 October 2007

UnitTest is part of the TestingFramework. It performs basic testing of individual code units.

---+++ How to use

On Unix, simply run

make test

It will run under Valgrind if configure did detect it.

Here is the sample output of a test from a real bug:

<verbatim> Testing "UT_LocaleTransactor" in ut_locale.t.cpp: ! ut_locale.t.cpp:35 strstr(msg, "1,0") == msg ok ! ut_locale.t.cpp:37 strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0 ok ! ut_locale.t.cpp:41 NOT(strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0) ok ! ut_locale.t.cpp:43 strstr(msg, "1.0") == msg ok ! ut_locale.t.cpp:44 strcmp(setlocale(LC_NUMERIC, NULL), "C") == 0 ok ! ut_locale.t.cpp:46 strcmp(setlocale(LC_NUMERIC, NULL), "fr_FR") == 0 FAILED ! ut_locale.t.cpp:48 strstr(msg, "1,0") == msg FAILED ! tf_test.cpp:119 new_valgrind_errs == old_valgrind_errs ok memleaks: sure:112 dubious:800 reachable:451080 suppress:0 ! tf_test.cpp:123 new_valgrind_leaks == old_valgrind_leaks ok </verbatim>

As you can see, some test pass, some fails. The last 3 lines are for Valgrind. If they fail, then there is a Valgrind error in the code: a memory leak.

---+++ How to write some

Writing UnitTest is not really hard, if you understand the code. Sometime it is tricky because some classes are not meant to be used alone.

---++++ Directory structure

Every directory that contains code has a =t= directory the contains its test.

The support code for the UnitTest is in =abi/src/af/tf/xp/=.

The files are organized to match the source code files. They have the same name but with the =.t.cpp= suffix. (=.t.mm= for Objective-C++ file where applicable).

---++++ One test

Here is a sample test for =UT_Vector=:

<verbatim> TFTEST_MAIN("UT_GenericVector basics") {

                 UT_GenericVector<char *> v;
                 TFPASS(v.getItemCount() == 0);
                 v.addItem("foo");
                 TFFAIL(v.getItemCount() == 0);

} </verbatim>

=TFTEST_MAIN= is a macro to declare the test function.

=TFPASS()= is a macro to check some condition that should be true

=TFFAIL()= is a macro to check a condition that should be false

---++++ Makefile

TBD

Personal tools