-
Notifications
You must be signed in to change notification settings - Fork 13
Running the test suite
3D Repo Bouncer has it own test suite for both unit tests (individual classes/functions) and system level testing(e.g. calling 3drepobouncerClient to import a model). There is also a separate test suite for bouncer wrapper.
This is driven by Google test. A test database is also used for tests that requires it.
Test source code can be found here: https://github.com/3drepo/3drepobouncer/tree/master/test/src
the main.cpp
is the entry point of the test suite
unit
folder contains unit tests, and system
folder contains system tests (a test that actually calls a compiled 3drepobouncerClient
Test data is used for some parts of the test suite (e.g. for read test on the MongoDBHandler). Just like 3drepo live data, the data is stored in 2 separate ways:
- Database data - dump of the test database can be found here: https://github.com/3drepo/tests/tree/master/cplusplus/bouncer/data/database/dump
- Fileshare - Copy of what the fileshare is expected to have can be found here: https://github.com/3drepo/tests/tree/master/cplusplus/bouncer/data/models/fileShare
It is expected that the test data is initialised to have the same state as what is presented in https://github.com/3drepo/tests/tree/master/cplusplus/bouncer/data
You will first have to restore the test data to a blank database. It is advised that you keep this database separate to your usual development database to avoid losing any working data. You can run mongod with a specified data directory to keep your data separate.
Mongo instance is expected to be running on localhost:27017
. Ensure this instance of the database does not have additional data (and it is not your development database!). You can then run mongorestore
to restore the database dump onto your active mongod
. I have the following powershell script to do this:
function resetTestDatabase{
$confirmation = Read-Host "Are you sure you're running the test database?!"
if ($confirmation -eq 'y') {
cd "C:\Users\Carmen\work\repo\tests\cplusplus\bouncer\data\database"
mongo --eval 'db.getMongo().getDBNames().forEach(function(i) {if(i!=\"admin\"){db.getSiblingDB(i).dropDatabase();}})'
mongo --eval 'db.getCollection('system.users').remove({user: {$ne: "admintesting"}})'
mongo admin --eval 'db.addUser("testUser", "3drepotest")'
mongorestore
}
}
You will have to change the directory it is cd
ing to your test repository. This script will both wipe the existing database, setup the relevant user and restore the database from dump.
The fileshare
is expected to be in the same place as where you are executing the test. for e.g. travis does a symlink to link the fileshare from the test repository to the current directly before running the test.
gtest is required to compile the tests. The version of gtest required is linked up as a submodule of 3drepobouncer: https://github.com/3drepo/3drepobouncer/tree/master/submodules. to pull this dependency, go to the root directory of the repository and run:
git submodule init
Then compile 3drepobouncer as normal, with REPO_BUILD_TEST flagged:
On successful compilation, you should see 3drepobouncerTest available in the bin
folder of your installation.
Set the environment variable REPO_MODEL_PATH
to the models
folder in the test repo. And execute the test by running the executable, 3drepobouncerTest.
This is a gtest executable, so all options available within gtest is available here, for e.g, to only run unit tests for RepoNode, you can add the following filter:
3drepobouncerTest --gtest_filter=RepoNodeTest.*
If you are struggling to get this working, have a look at the .travis.yml
in 3drepobouncer. This is the script that is passed to Travis CI in order to run the auto test thus it is a working example of how to get the test setup and working. Some guide points below:
- This line is how Travis is fetching the specific folder from the test repository (using SVN to reduce the amount of data we're getting, it's similar to just doing git clone.)
- It then goes into the database folder and do a mongorestore to restore the active database daemon with the test data
- It sets up the CMAKE to build with tests
- Sets env var path to point to the model folder
- And eventually calls the test suite to run