@@ -13,6 +13,42 @@ Main indicator of tests result is [exit code](http://tldp.org/LDP/abs/html/exit-
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](https://github.com/variety/variety/blob/master/test/src/main/java/com/github/variety/Variety.java).
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
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:
```
public void verifyResult(final String key, final double totalOccurrences, final double percentContaining, final 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`, method `runAnalysis()` and methods annotated with `@Test`.
...
...
@@ -22,7 +58,7 @@ Tests produce verbose log messages for detecting problems and errors.
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.
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.