|
1 | | -# Notes |
| 1 | +### Compiling/running unit tests |
| 2 | + |
| 3 | +Unit tests will be automatically compiled if dependencies were met in `./configure` |
| 4 | +and tests weren't explicitly disabled. |
| 5 | + |
| 6 | +After configuring, they can be run with `make check`. |
| 7 | + |
| 8 | +To run the pivxd tests manually, launch `src/test/test_pivx`. To recompile |
| 9 | +after a test file was modified, run `make` and then run the test again. If you |
| 10 | +modify a non-test file, use `make -C src/test` to recompile only what's needed |
| 11 | +to run the pivxd tests. |
| 12 | + |
| 13 | +To add more pivxd tests, add `BOOST_AUTO_TEST_CASE` functions to the existing |
| 14 | +.cpp files in the `test/` directory or add new .cpp files that |
| 15 | +implement new BOOST_FIXTURE_TEST_SUITE sections. |
| 16 | + |
| 17 | +To run the pivx-qt tests manually, launch `src/qt/test/test_pivx-qt` |
| 18 | + |
| 19 | +To add more pivx-qt tests, add them to the `src/qt/test/` directory and |
| 20 | +the `src/qt/test/test_main.cpp` file. |
| 21 | + |
| 22 | +### Running individual tests |
| 23 | + |
| 24 | +test_pivx has some built-in command-line arguments; for |
| 25 | +example, to run just the getarg_tests verbosely: |
| 26 | + |
| 27 | + test_pivx --log_level=all --run_test=getarg_tests |
| 28 | + |
| 29 | +... or to run just the doubledash test: |
| 30 | + |
| 31 | + test_pivx --run_test=getarg_tests/doubledash |
| 32 | + |
| 33 | +Run `test_pivx --help` for the full list. |
| 34 | + |
| 35 | +### Note on adding test cases |
| 36 | + |
2 | 37 | The sources in this directory are unit test cases. Boost includes a |
3 | | -unit testing framework, and since bitcoin already uses boost, it makes |
| 38 | +unit testing framework, and since pivx already uses boost, it makes |
4 | 39 | sense to simply use this framework rather than require developers to |
5 | 40 | configure some other framework (we want as few impediments to creating |
6 | 41 | unit tests as possible). |
7 | 42 |
|
8 | | -The build system is setup to compile an executable called "test_pivx" |
| 43 | +The build system is setup to compile an executable called `test_pivx` |
9 | 44 | that runs all of the unit tests. The main source file is called |
10 | 45 | test_pivx.cpp, which simply includes other files that contain the |
11 | 46 | actual unit tests (outside of a couple required preprocessor |
12 | | -directives). The pattern is to create one test file for each class or |
13 | | -source file for which you want to create unit tests. The file naming |
14 | | -convention is "<source_filename>_tests.cpp" and such files should wrap |
15 | | -their tests in a test suite called "<source_filename>_tests". For an |
16 | | -examples of this pattern, examine uint160_tests.cpp and |
17 | | -uint256_tests.cpp. |
| 47 | +directives). To add a new unit test file to our test suite you need |
| 48 | +to add the file to `src/Makefile.test.include`. The pattern is to |
| 49 | +create one test file for each class or source file for which you want |
| 50 | +to create unit tests. The file naming convention is |
| 51 | +`<source_filename>_tests.cpp` and such files should wrap their tests |
| 52 | +in a test suite called `<source_filename>_tests`. For an example of |
| 53 | +this pattern, examine `uint160_tests.cpp` and `uint256_tests.cpp`. |
18 | 54 |
|
19 | 55 | For further reading, I found the following website to be helpful in |
20 | 56 | explaining how the boost unit test framework works: |
21 | | -[http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/](http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/). |
| 57 | +[http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/](http://archive.is/dRBGf). |
0 commit comments