Motivating Data Storm
Data Storm is a free open source data base browser. While there are millions of data base browsers freely available online, Data Storm is differentas it can be launched directly from within your Java code. This enables you to see and modify data that otherwise may not be available to you.
The primary reason for creating Data Storm is to make test driven development (TDD) easier, when test involve databases. An often used technique is after executing a test case, to roll-back the data base. Frameworks such as Spring natively support this strategy. The roll-back happens irregardless of an error or succesful execution of the test case. The biggest draw back of this testing approach is that should a test case fail it can be very difficult to resolve the problem as you cannot see the data involved with the executing code. Such a situation is depicted below.
Did the test fail because no rows were inserted, or is the load() flawed? Or maybe its the constraints on the load() that prevents it from finding the order (maybe only non-closed orders are found, or orders after year 2000,...). Resolving such simple problems can be very tedious indeed due to the lack of access to the underlying data.
- Since the transaction is automatically rolled back at the end of the test an ordinary database browser cannot inspect the data.
- Since during the execution of a test, all database inserts, deletes and updates happens in an isolated transaction, an ordinary database browser cannot inspect the data available to the test method.
- Temporarily turning off the automatic roll-back after testing, can easily invalidate your existing reference data in the data base, hence requiring subsequent restoration (which may easily be quite time consuming).
Solution
Data Storm was invented to put the fun back into xUnit testing (at least for tests involving a database :-). It is simply a database viewer, that uses the same transaction as your tests, hence it has access to display or even modify your data! Launching requires the following code to be inserted just before the assertXX() that fails. The variable connection refers to your database connection established within your test code.new DataStorm().show( connection );Which when executed presents you with a window similar to the below where you can type in your queries. But even better, since you are launching Data Storm from within your Java tests, you can easily pass in context information to the query window, e.g. you can pass along id's such as
public void test_order_save() { Order orderToBeFound = new Order(SOME_ID, SOME_NAME1); orderToBeFound.save(); new DataStorm().show( connection, "SELECT * FROM orders o WHERE o.id = " + SOME_ID ); assertNotNull(orderToBeFound.load(SOME_ID)); }
Data Storm clearly shows us that data was in fact inserted, so attention must be targeted the load()... When Data Storm window is opened, one can fire any number of queries at the data base.
See also using data storm for more information.
Have fun!