JPA JUnit5 - Extension Parent

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-parent
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

pom
Description

Description

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

Project URL

https://github.com/jlmc/jpa-junit5-extensions
Source Code Management

Source Code Management

https://github.com/jlmc/jpa-junit5-extensions

Download jpa-junit5-parent

How to add to project

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

Dependencies

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

Project Modules

  • jpa-junit5-extension

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