JPA JUnit5 - Extension

This extension allow you to run Jpa integration tests without having to start any EntityManagerFactory for each test class.

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

io.github.jlmc
ArtifactId

ArtifactId

jpa-junit5-extension
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

jar
Description

Description

JPA JUnit5 - Extension
This extension allow you to run Jpa integration tests without having to start any EntityManagerFactory for each test class.

Download jpa-junit5-extension

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.jlmc/jpa-junit5-extension/ -->
<dependency>
    <groupId>io.github.jlmc</groupId>
    <artifactId>jpa-junit5-extension</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.jlmc/jpa-junit5-extension/
implementation 'io.github.jlmc:jpa-junit5-extension:1.1'
// https://jarcasting.com/artifacts/io.github.jlmc/jpa-junit5-extension/
implementation ("io.github.jlmc:jpa-junit5-extension:1.1")
'io.github.jlmc:jpa-junit5-extension:jar:1.1'
<dependency org="io.github.jlmc" name="jpa-junit5-extension" rev="1.1">
  <artifact name="jpa-junit5-extension" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.jlmc', module='jpa-junit5-extension', version='1.1')
)
libraryDependencies += "io.github.jlmc" % "jpa-junit5-extension" % "1.1"
[io.github.jlmc/jpa-junit5-extension "1.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api Optional jar 5.6.2

provided (1)

Group / Artifact Type Version
javax.persistence : javax.persistence-api jar 2.2

Project Modules

There are no modules declared in this project.

Java CI with Maven Maven Central

JPA JUnit 5 Extensions

This extension allow you to run Jpa integration tests without having to start any EntityManagerFactory for each test class.

How to use it?

Add the following dependency to your project:

<dependency>
  <groupId>io.github.jlmc</groupId>
  <artifactId>jpa-junit5-extension</artifactId>
  <version>1.1</version>
  <scope>test</scope>
</dependency>

NOTE:

This project depends on:

  • javax.persistence-api 2.2
  • JUnit Jupiter 5.6.2

Add the @JpaTest annotation to your test class. By default, Jpa EntityManagerFactory will be started in the callback BeforeAllCallback#beforeAll. Using the @JpaTest annotation to your test class, allows you to inject an instance of EntityManager, EntityManagerFactory or JpaProvider for each execution of the test methods:

@JpaTest( persistenceUnit = "it" )
class JUnit5Test {

    @JpaContext
    private JpaProvider jpa;

    @Test
    void createBook() {
        EntityManager em = jpa.em();
        em.getTransaction().begin();

        em.persist(new Book().setTitle("The Great Gatsby"));

        em.getTransaction().commit();

        em.close();
    }
}

Versions

Version
1.1
1.0