Variety tests
Tests are primary configured for Travis-CI platform. See .travis.yml
in repository (script
section).
Dependencies
MongoDB installed, of course. Tests are written in JUnit, using Java 8. Maven 3 is required.
You should have Java 8 and Maven installed. Junit and other dependencies are then automatically handled by Maven (see test/pom.xml
).
Run tests locally
Assuming running MongoDB, go to directory variety/test
(you should see pom.xml
there) and run mvn test
.
Main indicator of tests result is exit code of script.
In case of everything went well, return code is 0
. In case of tests fail, exit code is set to nonzero. Exit code is monitored by Travis-CI and informs about tests success or fail.
Tests produce verbose log messages for detecting problems and errors.
Java wrapper
The bridge between JUnit tests and Variety written in pure JS is Java wrapper for variety. Currently the wrapper is optimized for tests usage and allows:
- Specify analyzed DB and collection name
- Forward all config parameters to Variety.js
- execute mongo shell with all the config values and path to Variety
- Collect standard output of mongo shell
- Verify results values (assertion)
- Access mongo database through native java driver (initialization, cleanup)
Wrapper can be created with this command:
Variety wrapper = new Variety("test", "users");
Where the first parameter is analyzed database name and second analyzed collection name. Wrapper is written following builder pattern:
VarietyAnalysis analysis = new Variety("test", "users")
.withMaxDepth(10)
.withSort("{name:-1}")
.withLimit(5)
.runAnalysis();
VarietyAnalysis
is the actual analysis result. Main purpose is to easy verify results:
verifyResult(String key, double totalOccurrences, double percentContaining, String... types)
If the result does not match expectations, AssertionError is thrown (standard JUnit behavior).
Tests lifecycle
- Initialization, prepare data. Every test has method annotated with
@Before
. - Variety analysis, run variety.js against prepared data and verify results. See
Variety.java
, methodrunAnalysis()
and methods annotated with@Test
. - Resources cleanup, see method annotated with
@After
.
Used databases and collections
Tests use two databases, test
and varietyResults
. In DB test
, there will be created collection users
.
Collection is later analyzed by variety and results stored in DB varietyResults
, collection usersKeys
.
Cleanup method should remove both test and analysis data.
Contribute
You can extend current test cases or create new JUnit test. All tests under test/src/test/
are automatically included into run.