From 79e207a821bd78351d040f2d4a5772b01ed34a9c Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 29 Aug 2018 08:04:21 +0800 Subject: [PATCH] tests/README.md updated --- CMakeLists.txt | 20 ++++++-------- sql/openmonero.sql | 3 +- sql/openmonero_test.sql | 3 +- tests/README.md | 61 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c52dcb..9e107ac 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if (NOT MONERO_DIR) set(MONERO_DIR ~/monero) endif() -option(BUILD_TEST "Build tests for the project" ON) +option(BUILD_TEST "Build tests for the project" OFF) message(STATUS MONERO_DIR ": ${MONERO_DIR}") @@ -158,18 +158,16 @@ endif() target_link_libraries(${PROJECT_NAME} ${LIBRARIES}) -#set(COVERAGE_EXCLUDES 'ext/*' '${MONERO_DIR}/*') - -include_directories( +if (${BUILD_TEST}) + include_directories( ${CMAKE_SOURCE_DIR}/ext/googletest/googletest/include ${CMAKE_SOURCE_DIR}/ext/googletest/googlemock/include) - -#include_directories(${MONERO_DIR}/tests/core_tests) +endif() configure_files(${CMAKE_CURRENT_SOURCE_DIR}/sql ${CMAKE_CURRENT_BINARY_DIR}/sql) - - -enable_testing() -add_subdirectory(ext/googletest) -add_subdirectory(tests) +if (${BUILD_TEST}) + enable_testing() + add_subdirectory(ext/googletest) + add_subdirectory(tests) +endif() diff --git a/sql/openmonero.sql b/sql/openmonero.sql index d01e69d..9527ab0 100755 --- a/sql/openmonero.sql +++ b/sql/openmonero.sql @@ -23,7 +23,8 @@ SET time_zone = "+00:00"; -- Database: `openmonero` -- -USE openmonero; +CREATE DATABASE IF NOT EXISTS `openmonero` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; +USE `openmonero`; -- -------------------------------------------------------- diff --git a/sql/openmonero_test.sql b/sql/openmonero_test.sql index d1cb283..a9b7e72 100644 --- a/sql/openmonero_test.sql +++ b/sql/openmonero_test.sql @@ -23,7 +23,8 @@ SET time_zone = "+00:00"; -- Database: `openmonero_test` -- -USE openmonero_test; +CREATE DATABASE IF NOT EXISTS `openmonero_test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; +USE `openmonero_test`; -- -------------------------------------------------------- diff --git a/tests/README.md b/tests/README.md index 2d25ca4..dfb6894 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,3 +1,60 @@ -## Testing OpenMonero +## Testing openmonero -Description how to run tests etc. +[Googletest](https://github.com/google/googletest) and +[googlemock](https://github.com/google/googletest/tree/master/googlemock) +frameworks are used for unit testing of openmonero. There is no need +to install them, as they are provided with openmonero. + +### MySQL setup + +Testing openmonero's operations on MySQL database are performed using +actuall mysql database. For this purpose a testing database with +some pre-populated data is used: `openmonero_test`. Thus before +tests are run, make sure that `openmonero_test` database is initilized +using `openmonero/sql/openmonero_test.sql` file, and `database_test` contains +information on conneting to the test database in +`openmonero/config/config.json`. + +### Compile and run openmonero tests + +```bash +# go into build folder of openmonero +cd openmonero/build + +# indicate that test should be build +cmake .. -DBUILD_TEST=ON + +# compile openmonero with tests +make + +# run all tests +make test + +# the above command will produce summary of test results (shown below). +# for verbouse output, the following command can use +# make test ARGS=-V + +# individual tests executables can also be run. they are located in +# openmonero/build/tests + +``` + +Example test output is: + +```bash +mwo@arch:build$ make test +Running tests... +Test project /home/mwo/openmonero/build + Start 1: mysql_tests +1/4 Test #1: mysql_tests ...................... Passed 60.64 sec + Start 2: microcore_tests +2/4 Test #2: microcore_tests .................. Passed 1.67 sec + Start 3: bcstatus_tests +3/4 Test #3: bcstatus_tests ................... Passed 25.39 sec + Start 4: txsearch_tests +4/4 Test #4: txsearch_tests ................... Passed 1.04 sec + +100% tests passed, 0 tests failed out of 4 + +Total Test time (real) = 88.79 sec +```