Skip to content

Running the test suite

Carmen Fan edited this page Dec 13, 2023 · 1 revision

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.

Code structure

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

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:

Setting up test data

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.

Restoring the test database

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 cding 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.

Compiling 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: image

On successful compilation, you should see 3drepobouncerTest available in the bin folder of your installation.

Running the tests

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.*

Tips

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: