Showing posts from January, 2015

Using JUnit with GlassFish EJB embedded EJB container

1- Add the Glassfish embedded EJB container dependency to your Maven POM file. Also the JUnit dependency.
<dependency> <groupId>org.glassfish.main.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.1.2</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency> The scope is test so it can be applied during the testing of the application.

2- The service class is annotated with @Stateless as bellow
package; @Stateless public class MyService { public String getMessage() { return "Hello!"; } } For the sake of simplicity, the service class doesn't implement an interface as EJB supports injecting classes with no need to have interfaces.

3- Now the unit test class could be as bellow:
import javax.ejb.embeddabl…