flyway-spring4-test

Test slupport for Flyway based on springframework 4.

License

License

Categories

Categories

Flyway Data Databases
GroupId

GroupId

org.flywaydb.flyway-test-extensions
ArtifactId

ArtifactId

flyway-spring4-test
Last Version

Last Version

7.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

flyway-spring4-test
Test slupport for Flyway based on springframework 4.

Download flyway-spring4-test

How to add to project

<!-- https://jarcasting.com/artifacts/org.flywaydb.flyway-test-extensions/flyway-spring4-test/ -->
<dependency>
    <groupId>org.flywaydb.flyway-test-extensions</groupId>
    <artifactId>flyway-spring4-test</artifactId>
    <version>7.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.flywaydb.flyway-test-extensions/flyway-spring4-test/
implementation 'org.flywaydb.flyway-test-extensions:flyway-spring4-test:7.0.0'
// https://jarcasting.com/artifacts/org.flywaydb.flyway-test-extensions/flyway-spring4-test/
implementation ("org.flywaydb.flyway-test-extensions:flyway-spring4-test:7.0.0")
'org.flywaydb.flyway-test-extensions:flyway-spring4-test:jar:7.0.0'
<dependency org="org.flywaydb.flyway-test-extensions" name="flyway-spring4-test" rev="7.0.0">
  <artifact name="flyway-spring4-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.flywaydb.flyway-test-extensions', module='flyway-spring4-test', version='7.0.0')
)
libraryDependencies += "org.flywaydb.flyway-test-extensions" % "flyway-spring4-test" % "7.0.0"
[org.flywaydb.flyway-test-extensions/flyway-spring4-test "7.0.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.flywaydb.flyway-test-extensions : flyway-test jar 7.0.0
org.springframework : spring-test jar 4.3.25.RELEASE
org.springframework : spring-context jar 4.3.25.RELEASE
org.springframework : spring-jdbc jar 4.3.25.RELEASE
commons-dbcp : commons-dbcp jar 1.4

provided (1)

Group / Artifact Type Version
org.flywaydb : flyway-core jar 7.0.4

test (2)

Group / Artifact Type Version
junit : junit jar 4.13.1
com.h2database : h2 jar 1.4.197

Project Modules

There are no modules declared in this project.

flyway-test-extensions

flyway-test-extension logo

Test extensions for the Flyway project

For Flyway's features, see the Flyway Db Org Page

Version 7.0.0 Released

2020-10-22 flyway-test-extensions version 7.0.0 released.

Version number 7.0.x are used to show the dependency to Flyway version 7.0.x.

See also Release Notes

Central maven repository under http://search.maven.org/#search|ga|1|flyway-test-extensions contains all project jars.

Project

This extension gives the ability to reset and/or fill the database with defined content.
With this precondition, each test provides a reproducible database start point.

  • Annotation FlywayTest for database unit testing. Use Flyway feature.

    • clean - execution of flyway task clean
    • init - execution of flyway task init
    • migrate - execution of flyway task migrate
  • Annotation FlywayTest for a single database control.
    Annotation FlywayTests if more than one database must be controlled during a test.
    Annotations can be used

    Test Setup Junit 4 Junit 5 TestNG
    Once per Class
    Once per Class with test annotation @BeforeClass @BeforeAll @BeforeClass
    Once per Method @Before @BeforeEach @BeforeMethod
    per Method @Test @Test @Test
  • Sample projects on how to use the annotations inside a unit testing environment

  • Additional project supports a DBUnit annotation use together with FlywayTest DBUnitSupport. A usage example you will find at UsageFlywayDBUnitTest.

How to use it

The flyway test extensions are available at Maven Central.

For a detail usage description see the UsageFlywaySpringTest usage page.
Attention:

  • this version has a dependency on Spring 5.
  • The project is build with Java 8 compiler settings simular to Flyway project.
    If other compiler classes are needed use flyway-test-spring4 or flyway-test-spring3.

Integration

  • Add dependency to flyway-spring-test to your Maven pom file
    <dependency>
       <groupId>org.flywaydb.flyway-test-extensions</groupId>
       <artifactId>flyway-spring-test</artifactId>
       <version>7.0.0</version>
       <scope>test</scope>
    </dependency>
  • Extend your test class with the Spring test runner annotation (Junit 4).
    @RunWith(SpringRunner.class)
    @ContextConfiguration(locations = {"/context/simple_applicationContext.xml" })
    @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, 
                             FlywayTestExecutionListener.class })
  • Add the @FlywayTest annotation on each class or method were you need a clean database. You can also use the anntotation on class basis and every test method in the class where a clean database is also needed.
    // usage as once per class
    @FlywayTest
    public class Spring4JUnitTest 

    // another TestClass
    
    public class Spring4JUnitTest {
    
    // usage as per test method
    @Test
    @FlywayTest
    public void testMethod() { 
  • Add the @FlywayTests with @FlywayTest annotation on each class or method were you need a clean multiple database setup.
    // usage as once per class
    @FlywayTests(value = {
	@FlywayTest(flywayName = "flyway1"),   // Flyway configuration for database 1
	@FlywayTest(flywayName = "flyway2")    // Flyway configuration for database 2
    })
    public class Spring4JUnitTest 

    // another TestClass
    
    public class Spring4JUnitTest {
    
    // usage as per test method
    @Test
    @FlywayTests(value = {
	@FlywayTest(flywayName = "flyway3"), // Flyway configuration for database 3
	@FlywayTest(flywayName = "flyway4")  // Flyway configuration for database 4
    })
    public void testMethod() { 
  • Junit 5 support is only available together with Spring5 and need a different Spring setup.
    A step by step setup can be found here.
@ExtendWith({SpringExtension.class})
@ExtendWith({FlywayTestExtension.class})
@ContextConfiguration(locations = { "/context/simple_applicationContext.xml" })
@FlywayTest         // as class annotation
public class Junit5SpringTest ...

    @BeforeEach
    @FlywayTest(locationsForMigrate = {"loadmsqlbefore"})  // together with BeforeEach
    public void before() {
    ...

    @Test
    @FlywayTest       // as method annotation
    public void testMethodLoad() {
  • TestNG support is only available with Spring5 and need a different Test setup.
@ContextConfiguration(locations = {"/context/simple_applicationContext.xml"})
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
        FlywayTestExecutionListener.class})
@Test
@FlywayTest(locationsForMigrate = {"loadmsql"}) // execution once per class
public class MethodTest extends AbstractTestNGSpringContextTests {
    
    @BeforeClass
    @FlywayTest(locationsForMigrate = {"loadmsql"}) // execution once per class
    public static void beforeClass(
    
    @BeforeMethod
    @FlywayTest(locationsForMigrate = {"loadmsql"}) // execution before each test method
    public void beforeMethod(


    @Test
    @FlywayTest(locationsForMigrate = {"loadmsql"}) // as method annotation
    public void simpleCountWithoutAny(

Project depend on

Notes

  • The project depends on flyway version 7.0.4
  • The project will be supported until the extension will be integrated into the flyway project.
  • The project depends on Spring version 5.x (see flyway-spring5-test)
  • The project depends on Spring version 4.x (see flyway-spring4-test and flyway-dbunit-spring4-test)
  • The project depends on Spring version 3.2 (see flyways-swpring3-test and flyway-dbunit-spring3-test)
  • At the moment the code is tested with database H2 and Oracle.
    Only the DBunit part contains database specific code.
org.flywaydb.flyway-test-extensions

Flyway by Boxfuse

Database Migrations Made Easy by @boxfuse

Versions

Version
7.0.0
6.4.0
6.3.3
6.1.0
6.0.0
5.2.4
5.2.1
5.2.0
5.1.0
5.0.0
4.2.0.2
4.2.0.1
4.2.0
4.1.0
4.0.1
4.0
3.2.1.1
3.2.1
3.2
3.1
3.0.1
3.0