Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ride the database in JUnit tests with Database Rider

402 views

Published on

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!

Published in: Technology
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1url.pw/n9nxd ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I have found your program really helpful. It is so easy to understand. It makes far more sense than school teachers ever did. I desperately need a 'C' grade and with your package, I am bang on this pass rate. With a bit more revision, it will be a comfortable pass. Thanks Jeevan! ★★★ http://t.cn/AirraVnG
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Ride the database in JUnit tests with Database Rider

  1. 1. Ride the database in JUnit tests with Database Rider Mikalai Alimenkou @xpinjection https://t.me/xpinjection_channel https://xpinjection.com
  2. 2. Telegram channel https://t.me/xpinjection_channel
  3. 3. Disclaimer This talk is based on personal experience
  4. 4. Universal formula of success good tools OUR FOCUS TODAY!
  5. 5. Looking for motivation? https://www.youtube.com/watch?v=RanIHsirGFg https://jeeconf.com/program/test-driven-spring-boot- applications/
  6. 6. Some words about test data management https://seleniumcamp.com/talk/bro-manage-test-data-like-a-pro/
  7. 7. Don’t forget about practice!
  8. 8. This story has been started a long time ago with Unitils…
  9. 9. I was Unitils fan for many years… https://www.slideshare.net/alimenkou/java-unit-testing-with-unitils
  10. 10. Every story has an end  2014
  11. 11. 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
  12. 12. 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
  13. 13. Contribution is easy!
  14. 14. #1. Datasets management
  15. 15. Code examples on Github https://github.com/xpinjection/test-driven-spring-boot
  16. 16. 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
  17. 17. 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
  18. 18. #2. Data assertions
  19. 19. 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
  20. 20. 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
  21. 21. #3. Flexible configuration
  22. 22. 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
  23. 23. #4. Advanced features
  24. 24. 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
  25. 25. WTF?!? You told us this is very simple library!
  26. 26. 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
  27. 27. 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
  28. 28. @xpinjection https://xpinjection.com https://t.me/xpinjection_channel

×