Guice JPA JUnit Runner

A JUnit Runner allowing Guice-based testing with JPA Hibernate4-based. Each test method is running with a clean Injector instance.

License

License

Categories

Categories

JUnit Unit Testing Net GUI User Interface Guice Application Layer Libs Dependency Injection
GroupId

GroupId

net.lamberto.junit.jpa
ArtifactId

ArtifactId

guice-jpa-junit-runner
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Guice JPA JUnit Runner
A JUnit Runner allowing Guice-based testing with JPA Hibernate4-based. Each test method is running with a clean Injector instance.
Project URL

Project URL

https://github.com/marcolamberto/guice-jpa-junit-runner
Source Code Management

Source Code Management

https://github.com/marcolamberto/guice-jpa-junit-runner.git

Download guice-jpa-junit-runner

How to add to project

<!-- https://jarcasting.com/artifacts/net.lamberto.junit.jpa/guice-jpa-junit-runner/ -->
<dependency>
    <groupId>net.lamberto.junit.jpa</groupId>
    <artifactId>guice-jpa-junit-runner</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.lamberto.junit.jpa/guice-jpa-junit-runner/
implementation 'net.lamberto.junit.jpa:guice-jpa-junit-runner:1.0.1'
// https://jarcasting.com/artifacts/net.lamberto.junit.jpa/guice-jpa-junit-runner/
implementation ("net.lamberto.junit.jpa:guice-jpa-junit-runner:1.0.1")
'net.lamberto.junit.jpa:guice-jpa-junit-runner:jar:1.0.1'
<dependency org="net.lamberto.junit.jpa" name="guice-jpa-junit-runner" rev="1.0.1">
  <artifact name="guice-jpa-junit-runner" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.lamberto.junit.jpa', module='guice-jpa-junit-runner', version='1.0.1')
)
libraryDependencies += "net.lamberto.junit.jpa" % "guice-jpa-junit-runner" % "1.0.1"
[net.lamberto.junit.jpa/guice-jpa-junit-runner "1.0.1"]

Dependencies

compile (12)

Group / Artifact Type Version
net.lamberto.junit : guice-junit-runner jar 1.0.2
org.reflections : reflections jar 0.9.10
org.glassfish.web : el-impl jar 2.2
org.hsqldb : hsqldb jar 2.3.3
org.projectlombok : lombok jar 1.16.18
com.google.guava : guava jar 23.0
com.google.inject : guice jar 4.1.0
com.google.inject.extensions : guice-persist jar 4.1.0
org.slf4j : slf4j-api jar 1.7.12
ch.qos.logback : logback-classic jar 1.1.3
ch.qos.logback : logback-core jar 1.1.3
junit : junit jar 4.12

provided (5)

Group / Artifact Type Version
cglib : cglib-nodep jar 3.1
org.hibernate : hibernate-core jar 5.2.10.Final
org.hibernate : hibernate-entitymanager jar 5.2.10.Final
org.hibernate : hibernate-c3p0 jar 5.2.10.Final
org.hibernate : hibernate-validator jar 5.4.1.Final

test (2)

Group / Artifact Type Version
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

guice-jpa-junit-runner

Continuous Integration: Build Status

A Guice JPA JUnit Runner allowing Guice-based testing with JPA Hibernate4-based.

What is guice-jpa-junit-runner?

guice-jpa-junit-runner is a JUnit Runner allowing Guice-based testing with JPA entities. Each test method is running with a clean Injector instance.

Basic usage

@RunWith(GuiceJPAPersistJUnitRunner.class)
public class GuiceJPAPersistJUnitRunnerTest {
	@Inject
	public MyService service;

	@Test
	public void test() {
		// ...
	}
}

Using custom Guice modules

You can easily add one more modules by using the @GuiceModules annotation.

@RunWith(GuiceJPAPersistJUnitRunner.class)
@GuiceModules(TestModule.class)
public class GuiceJUnitRunnerTest {

	public static class TestModule extends AbstractModule {
		@Override
		protected void configure() {
			bind(MyService.class).to(MyServiceImpl.class);
			// ...
		}
	}


	@Inject
	public MyService service;

	@Test
	@GuiceModules(TestModule2.class)
	public void perTestSpecificModule() {
		// ...
	}

	@Test
	public void test() {
		// ...
	}
}

Configuring entities specific autodiscovery

public class TestModule extends GuiceJPAPersistModule {
	public TestModule() {
		super(
			SampleEntity.class.getPackage(),
			AnotherEntityWithDifferentPackage.class.getPackage()
		);
	}

	@Override
	protected void preConfigure() {
		// ...
	}

	@Override
	protected void postConfigure() {
		bind(MyService.class).to(MyServiceImpl.class);
		// ...
	}
}

Versions

Version
1.0.1
1.0.0