Tests are primary configured for [Travis-CI](https://travis-ci.org/variety/variety) platform. See `.travis.yml` in repository (`install` and `script` section).
It's easy to run tests locally, but you need to prepare your environment little bit. This readme assumes linux machine, mac would probably work too.
On windows you need [cygwin](http://www.cygwin.com) or some way how to run bash scripts.
Tests are primary configured for [Travis-CI](https://travis-ci.org/variety/variety) platform. See `.travis.yml` in repository (`script` section).
## Dependencies
[MongoDB](http://www.mongodb.org) installed, of course. Tests are written in [Jasmine](http://jasmine.github.io), Behavior-Driven JavaScript test framework.
In order to run Jasmine from command line, [Node.js](http://nodejs.org) is required.
Integration between Node.js and Jasmine ensures [jasmine-node](https://www.npmjs.org/package/jasmine-node) package.
Tests connect to MongoDB via node.js connector [node-mongodb-native](https://github.com/mongodb/node-mongodb-native).
[MongoDB](http://www.mongodb.org) installed, of course. Tests are written in [JUnit](http://junit.org/), using [Java 8](http://http://docs.oracle.com/javase/8/). [Maven 3](https://maven.apache.org/) 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
Install node dependencies globally. This step is necessary just for the first run. After that, packages are installed and ready to use.
```
npm install jasmine-node -g
npm install mongodb -g
```
Run `test/tests.sh` from repository base page. It will run whole lifecycle of tests.
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](http://tldp.org/LDP/abs/html/exit-status.html) 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.
## Tests lifecycle
- Initialization, prepare data, see `test/init.js`
- Variety analysis, run variety.js against prepared data
- Jasmine tests, see `test/variety_spec.js`
- Resources cleanup, see `test/cleanup.js`
- 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`.
- 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 script removes `test.users` and `varietyResults.usersKeys` after tests run. It does not remove any database.
Cleanup method should remove both test and analysis data.
## Contribute
You can extend `variety_spec.js` or create new JavaScript file with extension `_spec.js` (for example `max-depth_spec.js`).
All `_spec.js` files are automatically included in tests by jasmine.
\ No newline at end of file
You can extend current test cases or create new JUnit test. All tests under `test/src/test/` are automatically included into run.
Assert.assertEquals("Variety results have not correct count of entries",8,analysis.getResultsCollection().count());// 8 results, including '_id' and 'name'
// TODO: depth 3 means 'someNestedObject.a.b' or 'someNestedObject.a.b.c'? Documentation describes the first variant, variety counts also second.
// FIXME: Assert.assertEquals("Variety results have not correct count of entries", 5, analysis.getResultsCollection().count()); // 5 results, including '_id' and 'name'
Assert.assertEquals("5",params.get(Variety.PARAM_LIMIT));// TODO: why is limit configured to current count, not set as 'unlimited'? It could save one count query
}
/**
* Verify, that all passed parameters are correctly recognized and printed out in stdout of variety.