Skip to content

A library for running pgTAP tests using Testcontainers for Java

License

Notifications You must be signed in to change notification settings

opencastsoftware/pgtap-java

Repository files navigation

pgtap-java

CI Maven Central License

A library for running pgTAP tests using Testcontainers for Java.

A screenshot demonstrating pgTAP test results and descriptions displayed in the IntelliJ Run tool window

Installation

pgtap-java is published for Java 11 and above.

Gradle (build.gradle / build.gradle.kts):

testing {
    suites {
        val test by getting(JvmTestSuite::class) {
            dependencies {
                implementation("com.opencastsoftware:pgtap-java:0.1.0")
            }
        }
    }
}

Maven (pom.xml):

<dependency>
    <groupId>com.opencastsoftware</groupId>
    <artifactId>pgtap-java</artifactId>
    <version>0.1.0</version>
    <scope>test</scope>
</dependency>

Usage

pgtap-java is intended for use with JUnit 5 and Testcontainers for Java.

In order to run pgTAP tests with pgtap-java, you must extend the PgTapTest abstract class provided by this library.

PgTapTest requires 3 constructor parameters:

  • database: PostgreSQLContainer<?> - a Testcontainers PostgreSQL database container. This container image must have pgTAP preinstalled. See our postgres-with-pgtap Containerfile for an example of how you can do that.
  • pgTapTestPath: Path - the path to your pgTAP .sql test files
  • pgTapTmpPath: Path - the path where the pgTAP .sql test files will be mounted inside the PostgreSQL container.

In order for your tests to run, you should use withCopyFileToContainer to mount the pgTapTestsPath at pgTapTmpPath in your database container.

It doesn't matter precisely what pgTapTmpPath you use, as long as you use the same path in the constructor of PgTapTest and with withCopyFileToContainer.

See ExampleTest for an end-to-end example that uses Flyway migrations to set up a test database.

Acknowlegements

This project wouldn't exist without the work of theory, rnorth and the many pgTAP and Testcontainers contributors.

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENSE.

About

A library for running pgTAP tests using Testcontainers for Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published