git / moonbite-core / src/test/README.md · raw
# Unit testsThe sources in this directory are unit test cases. Boost includes aunit testing framework, and since Litecoin Core already uses Boost, it makessense to simply use this framework rather than require developers toconfigure some other framework (we want as few impediments to creatingunit tests as possible).The build system is set up to compile an executable called `test_litecoin`that runs all of the unit tests. The main source file for the test library is found in`util/setup_common.cpp`.### Compiling/running unit testsUnit tests will be automatically compiled if dependencies were met in `./configure`and tests weren't explicitly disabled.After configuring, they can be run with `make check`.To run the unit tests manually, launch `src/test/test_litecoin`. To recompileafter a test file was modified, run `make` and then run the test again. If youmodify a non-test file, use `make -C src/test` to recompile only what's neededto run the unit tests.To add more unit tests, add `BOOST_AUTO_TEST_CASE` functions to the existing.cpp files in the `test/` directory or add new .cpp files thatimplement new `BOOST_AUTO_TEST_SUITE` sections.To run the GUI unit tests manually, launch `src/qt/test/test_litecoin-qt`To add more GUI unit tests, add them to the `src/qt/test/` directory andthe `src/qt/test/test_main.cpp` file.### Running individual tests`test_litecoin` has some built-in command-line arguments; forexample, to run just the `getarg_tests` verbosely: test_litecoin --log_level=all --run_test=getarg_tests -- DEBUG_LOG_OUT`log_level` controls the verbosity of the test framework, which logs when atest case is entered, for example. The `DEBUG_LOG_OUT` after the two dashesredirects the debug log, which would normally go to a file in the test datadir(`BasicTestingSetup::m_path_root`), to the standard terminal output.... or to run just the doubledash test: test_litecoin --run_test=getarg_tests/doubledashRun `test_litecoin --help` for the full list.### Adding test casesTo add a new unit test file to our test suite you needto add the file to `src/Makefile.test.include`. The pattern is to createone test file for each class or source file for which you want to createunit tests. The file naming convention is `<source_filename>_tests.cpp`and such files should wrap their tests in a test suitecalled `<source_filename>_tests`. For an example of this pattern,see `uint256_tests.cpp`.### Logging and debugging in unit tests`make check` will write to a log file `foo_tests.cpp.log` and display this fileon failure. For running individual tests verbosely, refer to the section[above](#running-individual-tests).To write to logs from unit tests you need to use specific message methodsprovided by Boost. The simplest is `BOOST_TEST_MESSAGE`.For debugging you can launch the `test_litecoin` executable with `gdb`or `lldb` andstart debugging, just like you would with any other program:```bashgdb src/test/test_litecoin```