TestDataSet

Library to load test data to DB

Лицензия

Лицензия

Категории

Категории

Данные
Группа

Группа

com.jpragma
Идентификатор

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

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

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

0.1.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

TestDataSet
Library to load test data to DB
Ссылка на сайт

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

https://github.com/jpragma/testdataset
Система контроля версий

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

https://github.com/jpragma/testdataset

Скачать testdataset

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

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

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

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

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

TestDataSet is a simple java library that helps to populate tables in your relational database when writing unit/integration tests.

Quick start

  1. Create TestDataSetBuilder passing provider of java.sql.Connection to its constructor
  2. Use DSL to define tables, columns, and rows to insert (see example below)
  3. Call build() which returns an instance of TestDataSet
  4. In your unit test call TestDataSet.load() to populate the database with test data

Notes

  • You are responsible for creating transactions and rolling them back at the end of the test.
connection.setAutoCommit(false);
// ... 
connection.rollback();
  • When using Spring framework you can simply create a connection using org.springframework.jdbc.datasource.DataSourceUtils and transactions will automatically be started and rolled back at the end of the test.

Example

import com.jpragma.testdatasest.TestDataSet;
import com.jpragma.testdatasest.TestDataSetBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;
import java.time.LocalDate;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

@ExtendWith(SpringExtension.class)
@Transactional
@ContextConfiguration(classes = {PlayerConfig.class, TestDataSourceConfig.class})
class PlayerRepositoryTest {
    @Autowired
    private PlayerRepository repo;
    @Autowired
    private DataSource dataSource;

    private TestDataSet tds = new TestDataSetBuilder(() -> DataSourceUtils.getConnection(dataSource))
            .table("PLAYER")
                .columns("ID", "FIRST_NAME", "LAST_NAME", "JOINED_ON")
                .row(-1, "Isaac", "Levin", LocalDate.parse("2012-03-01"))
                .build();

    @Test
    void loadExistingPlayer() {
        tds.load();
        Optional<Player> player = repo.findById(-1);
        assertTrue(player.isPresent());
        assertEquals("Isaac", player.get().getFirstName());
    }
}

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

Версия
0.1.2