dataZ provides testing support for Datastores.
A typical Datastore is a database, either SQL or NoSql. But actually, any kind of (persistence) storage or with system with side effects like a data base could be a Datastore.
If you have to test a module which is using a Datastore, you have are facing some of these typical issues:
- Tests are slow.
- Tests are brittle.
- Tests are integration tests.
- Tests could not executed concurrent.
- How should I provide test data (test fixture), so that the tests are repeatable and independent.
- Test fixtures are hard to maintain: Just add a column to a table ...
- A complex query to a database is worth it's own unit test (even this kind of test some people won't call this an unit test at all).
- Mocks are ... (your choice :-))
More issues are
- The tests should be fast and so you decide to use a different database then the productive one (for example h2). But ...
- ... the tests should also be executed on the productive database.
- You have more then one datastore. For example: A single master database and for each tenant a different database instance.
- You have different types of datastores. For example: MySql and neo4j.
- You are making a product which is based on JPA, but every test should run also on any supported database.
- Performance tests with the productive database.
- and even more trouble...
Brief: Writing tests are a pain in the ass.
Everything which makes trouble, people try to avoid it. Another point is that is hard to apply TDD if a Datastore is part of your test.
So dataZ makes testing with Datastores a pleasure (again?).
- The general design goal is to provide a framework which works for any kind of Datastore.
- It should close the gap between unit and integration tests.
- Having a open and extendable framework which is adaptable to any specific needs of your project.
Under construction
TODO: Deploy to ???.
Currently are two Datastore implementations available:
TODO: Example repository
package com.company.module.my;
import org.failearly.dataz.junit4.DataSetDriver;
import org.failearly.dataz.DataSet;
// JUnit imports omitted for brevity
@DataSet // <<<<<< Expects data (setup) resource /com/company/module/my/MyTest.setup >>>>>>
public class MyTest {
@Rule public final TestRule _dataZ_Driver = DataSetDriver.createDataSetDriver(this); // <<<< This driver which applies the data resources on a datastores
@Test
public void testUsingClassDataSet() {
// Running your test against data resource /com/company/module/my/MyTest.setup
}
@Test @DataSet // <<<<<< Expects data (setup) resource /com/company/module/my/MyTest-testUsingMethodDataSet.setup >>>>>>
public void testUsingMethodDataSet() {
// Running your test against data resources
// /com/company/module/my/MyTest.setup
// and(!!) /com/company/module/my/MyTest-testUsingMethodDataSet.setup
}
}
Another possibility is to use a JUnit base class (AbstractDataSetTest) provided by dataZ.
package com.company.module.my;
import org.failearly.dataz.junit4.AbstractDataSetTest;
import org.failearly.dataz.DataSet;
// JUnit imports omitted for brevity
@DataSet
public class MyTest extends AbstractDataSetTest /* <<< Use this instead of TestRule >>>> */ {
@Test
public void testUsingClassDataSet() {
// ...
}
@Test @DataSet
public void testUsingMethodDataSet() {
// ...
}
}
If you want to report any issue or feature request, please do it here.
You can found me on