Thalia JUnit Rule for Testing with Postgres


Лицензия

Лицензия

Категории

Категории

JUnit Тестирование компонентов
Группа

Группа

de.thalia.junit
Идентификатор

Идентификатор

postgres-rule
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Thalia JUnit Rule for Testing with Postgres
Thalia JUnit Rule for Testing with Postgres
Ссылка на сайт

Ссылка на сайт

https://github.com/ThaliaBuecherGmbH/thalia-junit-postgres
Организация-разработчик

Организация-разработчик

Thalia Bücher GmbH
Система контроля версий

Система контроля версий

https://github.com/ThaliaBuecherGmbH/thalia-junit-postgres

Скачать postgres-rule

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/de.thalia.junit/postgres-rule/ -->
<dependency>
    <groupId>de.thalia.junit</groupId>
    <artifactId>postgres-rule</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.thalia.junit/postgres-rule/
implementation 'de.thalia.junit:postgres-rule:1.0.0'
// https://jarcasting.com/artifacts/de.thalia.junit/postgres-rule/
implementation ("de.thalia.junit:postgres-rule:1.0.0")
'de.thalia.junit:postgres-rule:jar:1.0.0'
<dependency org="de.thalia.junit" name="postgres-rule" rev="1.0.0">
  <artifact name="postgres-rule" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.thalia.junit', module='postgres-rule', version='1.0.0')
)
libraryDependencies += "de.thalia.junit" % "postgres-rule" % "1.0.0"
[de.thalia.junit/postgres-rule "1.0.0"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
ru.yandex.qatools.embed : postgresql-embedded jar 2.9
junit : junit jar 4.12
org.postgresql : postgresql jar 42.2.4

provided (1)

Идентификатор библиотеки Тип Версия
org.projectlombok : lombok jar 1.18.2

Модули Проекта

Данный проект не имеет модулей.

Thalia JUnit Rule for Embedded PostgreSQL testing

Build Status Maven Central

Why

We often write complex and PostgreSQL specific JDBC code. This code is hard to test using mocks and embedded databases like Derby or H2. To get full test coverage we need a real database, we need a PostgreSQL!

This JUnit Rule makes it easy to spawn an embedded PostgreSQL instance for your JUnit tests, control it and shut it down when you are finished.

Minimum requirements

  • Java 1.8

How

Add the following Maven dependency to your Maven project:

<dependency>
    <groupId>de.thalia.junit</groupId>
    <artifactId>postgres-rule</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

Unit testing is quite easy, just take a look at the following code to see it in action:

import org.junit.Rule;
import org.junit.Test;

import de.thalia.junit.postgres.*;

public class PostgresEmbedderRuleTest {

    @Rule
    public PostgresEmbedderRule postgresEmbedderRule = PostgresEmbedderRule
        .builder()
        .withVersion(PostgresEmbedder.PostgreVersion.V10_3)
        .build();
    
    @Test
    public void testRule() throws SQLException {
        // Here we get the JDBC Datasource to the embedded instance
        final DataSource source = postgresEmbedderRule.getDataSource();
        
        // Do some JDBC stuff
        final ResultSet result = source
            .getConnection()
            .createStatement()
            .executeQuery("select current_date");
            
        while(result.next()) {
        }
        result.close();
        
        // We are done!
    }
}
de.thalia.junit

Thalia Bücher GmbH

Версии библиотеки

Версия
1.0.0