Giter VIP home page Giter VIP logo

generator-jhipster-testcontainers's Introduction

generator-jhipster-testcontainers

NPM version Build Status Dependency Status

A Jhipster module to run integration tests with java Testcontainers

Introduction

This is a JHipster module to run Jhipster @SpringBootTest tests against on production database. A database container will automatically boot during the test startup phase.

Usage

npm install -g generator-jhipster-testcontainers

Run the module from your jhipster project folder:

yo jhipster-testcontainers

Run tests with the testcontainers spring profile

# maven
./mvnw verify -Dspring.profiles.active=testcontainers

# gradle
./gradlew integrationTest -Ptestcontainers

Example with mysql:

๐Ÿณ [mysql:8.0.19]                        : Creating container for image: mysql:8.0.19
๐Ÿณ [mysql:8.0.19]                        : Starting container with ID: ce2bc59ebbd1e02d0cffa6f04fca43a10c516818a2d8be90720f833a639151b6
๐Ÿณ [mysql:8.0.19]                        : Container mysql:8.0.19 is starting: ce2bc59ebbd1e02d0cffa6f04fca43a10c516818a2d8be90720f833a639151b6
๐Ÿณ [mysql:8.0.19]                        : Waiting for database connection to become available at jdbc:mysql://localhost:32770/academydb using query 'SELECT 1'
๐Ÿณ [mysql:8.0.19]                        : Container is started (JDBC URL: jdbc:mysql://localhost:32770/testdb)
๐Ÿณ [mysql:8.0.19]                        : Container mysql:8.0.19 started in PT17.8709687S
com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.

IMPORTANT: H2 will still be the default option, use testcontainers profile to test using testcontainers.

How it works

As for testcontainers documentation:

As long as you have Testcontainers and the appropriate JDBC driver on your classpath, you can simply modify regular JDBC connection URLs to get a fresh containerized instance of the database each time your application starts up.

This module simply adds a properties file in your test resources: application-testcontainers.yml and uses it when launching tests with testcontainers profile.

This is how mysql properties look like.

spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver
spring.datasource.url=jdbc:tc:mysql:8.0.19://hostname/testdb

Additional steps

Mysql, Postgres, Mariadb

No additional steps required

SQL Server

Due to licencing restrictions you are required to accept an EULA for this container image. To indicate that you accept the MS SQL Server image EULA, place a file at the root of the classpath named container-license-acceptance.txt, e.g. at src/test/resources/container-license-acceptance.txt. This file should contain the line:

mcr.microsoft.com/mssql/server:latest

Oracle

Modify the file testcontainers.properties, containing oracle.container.image=IMAGE, where IMAGE is a suitable image name and tag.

License

Apache-2.0 ยฉ Intesys Srl

generator-jhipster-testcontainers's People

Contributors

ecostanzi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.