For a long time DB related testing in Java world has been a real pain and most developers tried to reduce number of such tests as much as possible. With good in-memory database implementations like H2, schema migration solutions like Liquibase or Flyway, containerization with libraries like TestContainers, database management is now much simpler. But test data management is still a pain. Some developers use SQL dumps, others insert data via JPA/JDBC or rely on prepared data sets. Good old DBUnit may be a good option, but it is not so developer friendly and not adopted well for modern annotations driven development style. Database Rider closes the gap between modern Java development environment and DBUnit, bringing DBUnit closer to your JUnit tests, so database testing will feel like a breeze. In addition to flexible data sets management this library provides other useful features: programmatic data sets definition, leak hunting, data sets export, constraints management, etc. As contributor and loyal user for many years, I would like to share my experience with Database Rider and demonstrate how to make database testing a fun again!
12. Database Rider is a nice replacement
This project aims for bringing
DBUnit closer to your JUnit
tests so database testing will
feel like a breeze!
So you can ride the database
in your JUnit tests!
https://github.com/database-rider/database-rider
13. Why is it so good?
Open source with friendly contributors team
Minimal set of dependencies, pure JDBC
implementation
Simple, powerful and very flexible
Still wrapper around DBUnit with all it’s features
Integrations with JUnit 4/5, CDI and Cucumber
Advanced features like leak detection, constraints
management and datasets generation
Good documentation with many examples
17. Code examples on Github
https://github.com/xpinjection/test-driven-spring-boot
18. Basics features summary
YAML, JSON, XML, CSV and even Excel format support
Full set of data management strategies
Ability to carefully clear database before/after test
Extended DB configuration with SQL support
before/after test
Multiple datasets could be applied
19. Advanced features summary
DTD/XSD could be used for datasets validation
File and live templates in IDE simplify your life
Groovy and JavaScript for smart data generation
Export datasets with @ExportDataSet or
DataSetExporter to speed up datasets creation
Powerful export with SQL queries and tables filtering
Programmatic data sets creation with DataSetProvider
and DataSetBuilder
Meta-annotations for configuration reuse
22. Basics features summary
Several datasets could be specified in
@ExpectedDataSet for assertion
Some columns may be ignored for datasets reuse
Regular expressions for complex assertions
Ordering by set of columns
23. Advanced features summary
Configurable set of Replacers to implement custom
logic (nulls, date/time shift, etc.)
Programmatic provider to generate dataset from code
Contains and equals data comparison
26. Basics features summary
Global configuration in dbunit.yml
Local configuration at class/test level with @DBUnit
Executor scope for multiple logical databases support
EntityManagerProvider rule for JPA entity manager
provider
Merging of class and test level data sets
Externalized connection management
Configurable caching
29. Advanced features summary
Transactions management
Flexible table filtering and ordering for data cleanup
Disabling constraints to simplify data management
Connection leak detection
CDI integration
Cucumber integration
31. Summary and take aways
Database Rider simplifies your testing experience
You could use it for any kind of tests (unit, integration,
API, system)
Generate datasets where possible
Use full power of IDE to speed up datasets creation
Experiment with advanced features like leak detection
Contribute if your case is not covered
32. Resources and materials
https://github.com/xpinjection/test-driven-spring-boot - examples
from the talk
https://database-rider.github.io/database-rider/ - Database Rider
home page
https://database-rider.github.io/getting-started/ - getting started guide
https://github.com/database-rider/database-rider - project on Github
https://database-rider.github.io/database-
rider/1.7.3/documentation.pdf - current version of official
documentation