question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SpringBoot 2.x, JUnit5 and DatabaseRider configuration woes

See original GitHub issue

It seems that getting this combination of tools to work together isn’t sufficiently documented, I found the examples to be lacking. However, after a couple of hours of experimentation I was able to assemble a meta-annotation for myself that works as expected:

@SpringJUnitConfig
@DBUnit(
    caseInsensitiveStrategy = Orthography.LOWERCASE,
    cacheConnection = false,
    dataTypeFactoryClass = PostgresqlDataTypeFactory.class
)
@TestExecutionListeners(
    value = {
        DBRiderTestExecutionListener.class,
        TransactionalTestExecutionListener.class,
        DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class
    },
    mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
)
@DirtiesContext
@SpringBootTest(
    webEnvironment= SpringBootTest.WebEnvironment.NONE
)
@Transactional
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DBIntegrationTest {
}

Am I doing too much configuration here? Is there something I missed? I’m glad that I was able to find a working configuration, but the samples/examples that I have seen published lead me to believe that a simpler configuration should have been possible…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
arhohuttunencommented, May 8, 2020

I agree, this is something only Spring specific.

A lot of this was hidden because I didn’t know that @DataJpaTest adds a @Transactional annotation, and now I’m considering changing the default and cleaning up some tests the dbunit way. They mostly already work because of the default seeding strategy anyway.

1reaction
mutsyscommented, Mar 22, 2020

no problem. i will put together an example repo for you that reproduces the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing the Persistence Layer With Spring Boot @DataJpaTest
This tool utilizes DBUnit, which uses datasets to put the database into a known state. Database Rider allows the datasets to be written...
Read more >
How to re-create database before each test in Spring?
I.e. how to make database recreate before each test as it happens at application first start? As you see, I tried @DirtiesContext at...
Read more >
junit-team/junit5 - Gitter
Though Database Rider seems to be the only extension for JUnit Jupiter posted there that provides support for DbUnit. Eric Turley.
Read more >
Writing Tests with JUnit 5 | The IntelliJ IDEA Blog
In this tutorial we're going to look at features of JUnit 5 that can make it easier for us to write effective and...
Read more >
Ride the database in JUnit tests with Database Rider
Database Rider closes the gap between modern Java development environment and DBUnit, bringing DBUnit closer to your JUnit tests, so database testing will ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found