All Projects → radcortez → flyway-junit5-extensions

radcortez / flyway-junit5-extensions

Licence: Apache-2.0 License
Flyway JUnit 5 Extension to clean / migrate your database in tests.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to flyway-junit5-extensions

osgi-test
Testing support for OSGi. Includes JUnit 4 and JUnit 5 support and AssertJ support.
Stars: ✭ 22 (+57.14%)
Mutual labels:  test, junit, junit5
spring-jooq-flyway-testcontainers-junit5
🚀 Example project with configured Spring Boot, JooQ, TestContainers, MySQL container and JUnit5
Stars: ✭ 29 (+107.14%)
Mutual labels:  junit, flyway, junit5
jpa-unit
JUnit extension to test javax.persistence entities
Stars: ✭ 28 (+100%)
Mutual labels:  test, junit, junit5
unittest expander
A library that provides flexible and easy-to-use tools to parameterize Python unit tests, especially those based on unittest.TestCase.
Stars: ✭ 12 (-14.29%)
Mutual labels:  test, tests
scalatest-junit-runner
JUnit 5 runner for Scalatest
Stars: ✭ 30 (+114.29%)
Mutual labels:  test, junit
advanced-spring-scaffold
This project provides an advanced baseline to help you kick start a Spring project.
Stars: ✭ 21 (+50%)
Mutual labels:  flyway, junit5
playwright-test
Run unit tests with several runners or benchmark inside real browsers with playwright.
Stars: ✭ 81 (+478.57%)
Mutual labels:  test, tests
webdrivermanager-examples
JUnit tests with Selenium WebDriver and WebDriverManager
Stars: ✭ 94 (+571.43%)
Mutual labels:  junit, junit5
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (+57.14%)
Mutual labels:  test, tests
manon
🧪 Play with SpringBoot 2, JWT, Querydsl, GraphQL, Docker, ELK, PostgreSQL, MariaDB, Redis, MongoDB, Flyway, Maven, Gradle, TestNG, JUnit5, JaCoCo, GreenMail, CI, Quality Gates, Prometheus, Gatling, etc.
Stars: ✭ 26 (+85.71%)
Mutual labels:  flyway, junit5
dojos
Alguns desafios para os participantes dos grupos de estudo
Stars: ✭ 33 (+135.71%)
Mutual labels:  test, tests
testing-spring-boot-applications-masterclass
🍃 Everything You Need to Know About Testing Spring Boot Applications
Stars: ✭ 185 (+1221.43%)
Mutual labels:  junit, junit5
to-string-verifier
To String Verifier provides an easy and convenient way to test the toString method on your class.
Stars: ✭ 25 (+78.57%)
Mutual labels:  test, junit
action-junit-report
Reports junit test results as GitHub Pull Request Check
Stars: ✭ 103 (+635.71%)
Mutual labels:  test, junit
ForgeModdingSkeleton
Skeletons for building Forge mods
Stars: ✭ 21 (+50%)
Mutual labels:  junit, junit5
kit-assignment-tests
Test collection for KIT programming assignments (WS16/17)
Stars: ✭ 18 (+28.57%)
Mutual labels:  test, junit
junit-annotate-buildkite-plugin
📈 Summarise your test failures as a build annotation
Stars: ✭ 18 (+28.57%)
Mutual labels:  tests, junit
PixelTest
Fast, modern, simple iOS snapshot testing written purely in Swift.
Stars: ✭ 56 (+300%)
Mutual labels:  test, tests
junit5-demo
Demos for JUnit 5
Stars: ✭ 46 (+228.57%)
Mutual labels:  junit, junit5
CI-Report-Converter
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).
Stars: ✭ 17 (+21.43%)
Mutual labels:  test, junit

License Maven Build

Flyway JUnit 5 Extensions

This extensions allows you to clean / migrate your database using Flyway during testing.

How to use it?

Add the following dependency to your project:

<dependency>
  <groupId>com.radcortez.flyway</groupId>
  <artifactId>flyway-junit5-extension</artifactId>
  <version>1.3.0</version>
  <scope>test</scope>
</dependency>

NOTE:

This project depends on:

  • Flyway 8.4.4
  • JUnit Jupiter 5.8.2

Add the @FlywayTest annotation to your test class or method. By default, Flyway will perform the migrate action before each test execution and the clean action after the test. This can be disabled by turning clean = false in the @FlywayTest annotation.

The only required information in the @FlywayTest annotation is the database information that you can supply using the inner @DataSource annotation. In the @DataSource annotation you can specify the url, username and password to connect to a running database:

@FlywayTest(@DataSource(url = "jdbc:h2:mem:test"))
class JUnit5Test {

}

Or you can implement a DataSourceProvider and return a DataSourceInfo with the database connection details:

@FlywayTest(@DataSource(JUnit5Test.H2DatasourceProvider.class))
class JUnit5Test {

    static class H2DatasourceProvider implements DataSourceProvider {
        @Override
        public DataSourceInfo getDatasourceInfo(final ExtensionContext extensionContext) {
            return DataSourceInfo.config("jdbc:h2:mem:test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1");
        }
    }
}

The DataSourceProvider will always take priority over url, username and password in the @DataSource annotation.

The @FlywayTest annotation can also be placed in a method.

@FlywayTest(additionalLocations = "db/additionalLocation")
void additionalLocations() throws Exception {

}

When both the class and the method are annotated, the annotations metadata is merged with the method annotation taking priority over the class annotation.

Conventions

The extension uses the default path to load migration scripts from Flyway, set in resources/db/migration.

If you want to add specific database migrations to a particular test, you can place the migration files in resources/db/ plus the fully qualified name of the test as a path. For instance com/radcortez/flyway/test/junit/H2LocationTest.

Additional migration locations can be defined using the additionalLocations metadata in the @FlywayTest annotation. This will not override the default locations, but just add a location for the migration files.

Meta Annotations

You can also place the @FlywayTest annotation in a meta annotation and then use it in the test class.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@FlywayTest(value = @DataSource(url = "jdbc:h2:mem:test"))
public @interface H2 {

}

@H2
class H2MetaAnnotationTest {
    
}

The @H2 annotation is already available in the extension, but you need to remember to add the H2 dependency to your project to be able to use an H2 database:

<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <version>2.1.210</version>
  <scope>test</scope>
</dependency>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].