db-util
db-util copied to clipboard
Create a JUnit 5 extension to for clearer tests
Currently, we need to write tests like:
@Test
public void test() {
SQLStatementCountValidator.reset();
warehouseProductInfoService.findAllWithNPlusOne();
assertSelectCount(1);
}
It would be useful if we could write
@ExtendWith(QueryCountExtension.class)
public class Tests {
@QueryCount(select = 1)
public void test() {
warehouseProductInfoService.findAllWithNPlusOne();
}
}
I can have a look at creating a pull request, but I wanted to get your feedback on whether this is something you'd be interested in and how you'd like the @QueryCount
annotation to look like. I was thinking of having something like (with defaults): @QueryCount(select = 0, insert = 0, update = 0, delete = 0, total = <sum of others>)
I'd also suggest a number of methods that take a lambda:
assertSelectCount(1, () -> warehouseProductInfoService.findAllWithNPlusOne());
so that you can do multiple assertions in the same test.
Looks like a good idea. Send me a Pull Request with a proposal for this.
The project will be archived soon.