Skip to content

A demonstration project that shows how to take advantage of Guice in JUnit tests

Notifications You must be signed in to change notification settings

accelad-com/GuiceJUnitRunner

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guice-JUnit

Guice-JUnit is based on the demonstration project of https://github.com/sfragis/GuiceJUnitRunner. It enables injection of Guice modules in unit tests.

As an added extra this library also includes support for Mybatis+Guice transactions, inspired by http://mybatis-user.963551.n3.nabble.com/How-to-rollback-all-changes-in-a-JUnit-test-td3181475.html

To use this library, include it in your project:

<dependency>
	<groupId>nl.pvanassen</groupId>
	<artifactId>guice-junit-runner</artifactId>
	<version>1.1.0</version>
	<scope>test</scope>
</dependency>

To set up a test with the junit runner, use the RunWith annotation to point to GuiceJUnitRunner. Also supply the required modules to load

@RunWith(GuiceJUnitRunner.class)
@GuiceModules({ ComponentsTestModule.class, ServicesTestModule.class })

For an example see https://github.com/pvanassen/GuiceJUnitRunner/blob/master/src/test/java/nl/pvanassen/guicejunitrunner/JavaxInjectPropertyTest.java

To enable MyBatis transactions, instead use:

@RunWith(GuiceMyBatisRollbackJUnitRunner.class)
@GuiceModules({ ComponentsTestModule.class, ServicesTestModule.class })

Make sure Mybatis is initialized in one of your modules.

About

A demonstration project that shows how to take advantage of Guice in JUnit tests

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%