# Java repositories testing

DevFeed: [Java repositories testing](<https://devfeed.tech/articles/java-repositories-testing-27263.md>)

Original publisher: [Read original article](<https://blog.pchudzik.com/201611/java-repository-testing/>)

Published: 2016-11-06T00:00:00Z

Content type: tutorial

Language: en

Sources: [Paweł Chudzik](<https://devfeed.tech/sources/pawe-chudzik.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Java](<https://devfeed.tech/topics/java.md>), [Hibernate](<https://devfeed.tech/topics/hibernate.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [Spring Boot](<https://devfeed.tech/topics/spring-boot.md>)

Tags: [hibernate](<https://devfeed.tech/tags/hibernate.md>), [java](<https://devfeed.tech/tags/java.md>), [spring-boot](<https://devfeed.tech/tags/spring-boot.md>), [sql](<https://devfeed.tech/tags/sql.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>)

## AI overview

A tutorial on testing Java repository layers, motivated by a slow SQL query in a Hibernate-based application. It recommends detailed tests, production-like database setup, migration scripts, and running CI tests against the production database technology.

## Source excerpt

A few days ago I've stumbled upon SQL query performance issue. Git claims that I was the author so maybe that's the reason I remember this feature. There was like 3 classes, everything was super easy and super fast all I needed to do was to let Hibernate do its thing. Then time passed, new features were requested, the model becomes more complex, the number of rows increased to ~4 million and original query became too slow. When working on query optimization I was really happy to find that detailed tests are in place. With proper test setup I was able to test my new query to make sure all requirements are met and then quickly copy paste query to sqldeveloper run it on a test environment and verify if performance is acceptable. It wasn't simple query and it took me some time to figure out how to make it quick and work exactly as old one. That was the time I was really glad that we invested in detailed unit tests in the beginning. Read more