io.github.nblxa:turntables

Turntables - parent module

License

License

GroupId

GroupId

io.github.nblxa
ArtifactId

ArtifactId

turntables
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

pom
Description

Description

io.github.nblxa:turntables
Turntables - parent module
Project URL

Project URL

http://github.com/nblxa/turntables
Source Code Management

Source Code Management

https://github.com/nblxa/turntables

Download turntables

Filename Size
turntables-0.2.0.pom 6 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.nblxa/turntables/ -->
<dependency>
    <groupId>io.github.nblxa</groupId>
    <artifactId>turntables</artifactId>
    <version>0.2.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/io.github.nblxa/turntables/
implementation 'io.github.nblxa:turntables:0.2.0'
// https://jarcasting.com/artifacts/io.github.nblxa/turntables/
implementation ("io.github.nblxa:turntables:0.2.0")
'io.github.nblxa:turntables:pom:0.2.0'
<dependency org="io.github.nblxa" name="turntables" rev="0.2.0">
  <artifact name="turntables" type="pom" />
</dependency>
@Grapes(
@Grab(group='io.github.nblxa', module='turntables', version='0.2.0')
)
libraryDependencies += "io.github.nblxa" % "turntables" % "0.2.0"
[io.github.nblxa/turntables "0.2.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Turntables

Maven Central CircleCI Coverage Status Quality Gate Status

Turntables enables developers to write test assertions for data in tables using a simple fluent interface.

IntelliJ diff in comparison mode

Assertion errors are shown in an IDE-friendly way. The screenshot above demonstrates how IntelliJ IDEA highlights the differences between the actual and expected tables in the sample test.

  @Test
  public void test() {
    Tab actual = Turntables.tab()
        .col("name").key("id")
        .row("Elise", 1)
        .row("Bob", 2);

    Turntables.assertThat(actual)
        .colMode(Settings.ColMode.MATCH_BY_NAME)
        .rowMode(Settings.RowMode.MATCH_BY_KEY)
        .matches()
        .key("id").col("name")
        .row(1, "Alice")
        .row(2, "Bob")
        .asExpected();
  }

JUnit support

Turntables integrates with JUnit to help developers set up initial test data in tables:

@Rule
public TestDataSource testDataSource = TestDataFactory.jdbc(
        "jdbc:mysql://localhost:3306/mydb", "testuser", "str0ngPA55word!");

@TestTable(name = "employees", cleanUpAction = CleanUpAction.DROP)
public Tab testTab = Turntables.tab()
  .col("id").col("name")
  .row(1, "Alice")
  .row(2, "Bob");

Use the table name in test methods to get its contents for assertions.

Tab actual = testDataSource.ingest("employees");

For a complete example with MySQL, see ITMySql.java.

For Oracle, see: ITOracle.java.

Difference to AssertJ-DB

Turntables's main power and difference from AssertJ-DB is the ability to match whole table contents at once using specific rules (e.g. match rows by key or match columns by name) and to present to the developer only the difference that matters for the assertion.

As a result, less code must be written for tests and it's easier to find bugs.

Maven

Turntables extends AssertJ and you'll need both dependencies.

<dependency>
  <groupId>io.github.nblxa</groupId>
  <artifactId>turntables-core</artifactId>
  <version>0.2.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>io.github.nblxa</groupId>
  <artifactId>turntables-mysql</artifactId>
  <version>0.2.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-core</artifactId>
  <version>3.18.1</version>
  <scope>test</scope>
</dependency>

The above example uses a MySQL 8 dependency. If you use Turntables with another JDBC database, see JDBC for additional dependencies.

Build

A quick build skipping integration tests:

./mvnw clean package

Integration tests use Docker.

The Oracle test is containerized using the image quillbuilduser/oracle-18-xe.

Image size is 13GB at the time of writing this, so it's advisable to download it beforehand.

Build with integration tests:

docker run --rm -itd --name oracle -p 1521:1521 quillbuilduser/oracle-18-xe
docker run --rm -itd --name mysql -e MYSQL_ROOT_PASSWORD=tiger -e MYSQL_DATABASE=testdb -p 3306:3306 mysql:8.0.22
( docker logs -f mysql & ) | grep -m1 'MY-010931'
( docker logs -f oracle & ) | grep -m1 'DATABASE IS READY TO USE!'
./mvnw clean verify || true
docker stop oracle 2>/dev/null || true
docker stop mysql 2>/dev/null || true

Versions

Version
0.2.0
0.1.0