AssertJ-DB provides assertions to test data in a database. It requires Java 7 or later and can be used with either JUnit or TestNG.
If you need additional assertions, please create a ticket in the AssertJ-DB issue tracker.
AssertJ-DB is hosted on github : https://github.com/assertj/assertj-db.
Big thanks to Joel Costigliola for his welcome, for his help and for having accepted to associate this project with a great project like AssertJ.
Régis Pouiller (AssertJ-DB creator)Suppose that the database contains this table :
ID | NAME | FIRSTNAME | SURNAME | BIRTHDATE | SIZE |
---|---|---|---|---|---|
1 | 'Hewson' | 'Paul David' | 'Bono' | 05-10-60 | 1.75 |
2 | 'Evans' | 'David Howell' | 'The Edge' | 08-08-61 | 1.77 |
3 | 'Clayton' | 'Adam' | 03-13-60 | 1.78 | |
4 | 'Mullen' | 'Larry' | 10-31-61 | 1.70 |
To quickly start using DataBase assertions, follow the steps below.
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-db</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
If you use another dependency tool, please check this page to find the relevant assertj-db dependency declaration for your tool.
... and use your preferred IDE code completion after assertThat.
Example from TableAssertionExamples.java :
import static org.assertj.db.api.Assertions.assertThat;
import org.assertj.db.type.DateValue;
import org.assertj.db.type.Table;
Table table = new Table(dataSource, "members");
// Check column "name" values
assertThat(table).column("name")
.value().isEqualTo("Hewson")
.value().isEqualTo("Evans")
.value().isEqualTo("Clayton")
.value().isEqualTo("Mullen");
// Check row at index 1 (the second row) values
assertThat(table).row(1)
.value().isEqualTo(2)
.value().isEqualTo("Evans")
.value().isEqualTo("David Howell")
.value().isEqualTo("The Edge")
.value().isEqualTo(DateValue.of(1961, 8, 8))
.value().isEqualTo(1.77);
In this simple example you can see many concepts of AssertJ-DB (the concepts are simple but I advice you to take the time to get to know them well) :
column("name")
moves the assertion to the column),
from this column to the first value (the first call of value()
moves to the first value)
and after that to each value (each call of value()
moves to the next value of the column).
row(1)
moves the assertion to the row),
from this row to the first value
and after that to each value (value()
calls have similar behavior for rows and columns).
Release date : 2019-12-26 (dependency declaration)
Latest javadoc release : AssertJ DB javadoc.
See some of AssertJ-DB noteworthy features to get the maximum of it !
You can learn more by looking at the AssertJ-DB javadoc.
Another way is to take a look at the assertj-db-examples tests. They show what is possible with AssertJ DB Assertions with running code. You can clone the repository and run its tests !
If you have any questions, please use the AssertJ google group.
AssertJ-DB is hosted on github : https://github.com/assertj/assertj-db.
Please report bugs or missing features in the AssertJ-DB issue tracker.
Thanks for your interest ! Please check our contributor's guidelines.