Java Reference
In-Depth Information
@Before
public void setUp() {
ec = EJBContainer.createEJBContainer();
ctx = ec.getContext();
}
The testReturnMessage method, annotated with org.junit.Test to indicate
that the method includes a unit test, obtains a reference to StandaloneBean through
the Context instance, and calls StandaloneBean.returnMessage . The result is
compared with the expected result using a JUnit assertion, assertEquals . If the string
returned from StandaloneBean.returnMessage is equal to “Greetings!” the test
passes.
Click here to view code image
@Test
public void testReturnMessage() throws Exception {
logger.info("Testing stan-
dalone.ejb.StandalonBean.returnMessage()");
StandaloneBean instance = (StandaloneBean)
ctx.lookup("java:global/classes/StandaloneBean");
String expResult = "Greetings!";
String result = instance.returnMessage();
assertEquals(expResult, result);
}
Finally, the tearDown method, annotated with org.junit.After to indicate that the
method should be executed after all the unit tests have run, closes the embedded container
instance.
@After
public void tearDown() {
if (ec != null) {
ec.close();
}
}
Search WWH ::




Custom Search