1
+ # Unit tests
2
+
3
+ The sources in this directory are unit test cases. Boost includes a
4
+ unit testing framework, and since Bitcoin Core already uses Boost, it makes
5
+ sense to simply use this framework rather than require developers to
6
+ configure some other framework (we want as few impediments to creating
7
+ unit tests as possible).
8
+
9
+ The build system is set up to compile an executable called ` test_bitcoin `
10
+ that runs all of the unit tests. The main source file is called
11
+ ` setup_common.cpp ` .
12
+
1
13
### Compiling/running unit tests
2
14
3
15
Unit tests will be automatically compiled if dependencies were met in ` ./configure `
@@ -12,7 +24,7 @@ to run the bitcoind tests.
12
24
13
25
To add more bitcoind tests, add ` BOOST_AUTO_TEST_CASE ` functions to the existing
14
26
.cpp files in the ` test/ ` directory or add new .cpp files that
15
- implement new BOOST_AUTO_TEST_SUITE sections.
27
+ implement new ` BOOST_AUTO_TEST_SUITE ` sections.
16
28
17
29
To run the bitcoin-qt tests manually, launch ` src/qt/test/test_bitcoin-qt `
18
30
@@ -32,20 +44,24 @@ example, to run just the getarg_tests verbosely:
32
44
33
45
Run ` test_bitcoin --help ` for the full list.
34
46
35
- ### Note on adding test cases
36
-
37
- The sources in this directory are unit test cases. Boost includes a
38
- unit testing framework, and since bitcoin already uses boost, it makes
39
- sense to simply use this framework rather than require developers to
40
- configure some other framework (we want as few impediments to creating
41
- unit tests as possible).
47
+ ### Adding test cases
42
48
43
- The build system is setup to compile an executable called ` test_bitcoin `
44
- that runs all of the unit tests. The main source file is called
45
- setup_common.cpp. To add a new unit test file to our test suite you need
49
+ To add a new unit test file to our test suite you need
46
50
to add the file to ` src/Makefile.test.include ` . The pattern is to create
47
51
one test file for each class or source file for which you want to create
48
- unit tests. The file naming convention is ` <source_filename>_tests.cpp `
52
+ unit tests. The file naming convention is ` <source_filename>_tests.cpp `
49
53
and such files should wrap their tests in a test suite
50
54
called ` <source_filename>_tests ` . For an example of this pattern,
51
- examine ` uint256_tests.cpp ` .
55
+ see ` uint256_tests.cpp ` .
56
+
57
+ ### Logging and debugging in unit tests
58
+
59
+ To write to logs from unit tests you need to use specific message methods
60
+ provided by Boost. The simplest is ` BOOST_TEST_MESSAGE ` .
61
+
62
+ For debugging you can launch the test_bitcoin executable with ` gdb ` or ` lldb ` and
63
+ start debugging, just like you would with bitcoind:
64
+
65
+ ``` bash
66
+ gdb src/test/test_bitcoin
67
+ ```
0 commit comments