Originally posted by Mattias Arthursson:
Typically you would not mock any components in end-to-end tests. Use mocks for you unit tests (i.e. each unit in isolation). You should be able to make your mocks throw the appropriate exceptions as well (using easymock, use mockControl.expectAndThrow() or mockControl.setThrowable()). End-to-end testing should be performed on the full, running system (in a test environment that is).
First of all let me thank for the quick response..
Actually i'm looking at an example which is combination of both easymock and cactus...i thought i would be able to do end-end incontainer testing in testenvironment.using this example as basis I want come up with a framework ,My only concern how to use with our existing design,I already i've client which is gateway for all method calls to sessionSercie bean and also have some logic in it how i should mock my client as well as my remote session bean and to run to end-end testing.Example i used is from mockEJB website,
http://www.mockejb.org/java2html/org/mockejb/test/FundamentalsTest.java.html Example
In the Test.class setup
{
externalServiceControl.getMock();
mockContainer.deploy( new SessionBeanDescriptor( ExternalService.JNDI_NAME,
ExternalServiceHome.class, ExternalService.class,
externalServiceBean ) );
// All EJBs are now deployed
// To get the Sample bean we use the standard J2EE routine
// Lookup the home
Object sampleHomeObj = context.lookup( SampleService.JNDI_NAME );
// PortableRemoteObject does not do anything in our case but we can still call it
sampleServiceHome = (SampleServiceHome) PortableRemoteObject.narrow
(sampleHomeObj,SampleServiceHome.class );
// create the bean
sampleService = sampleServiceHome.create(); ---Service Sessionbean
}
public void testSimpleCalls() throws Exception {
externalServiceBean.sampleMethod();
externalServiceControl.setReturnValue("sample string");
externalServiceControl.replay();
// Call a simple business method
String s = sampleService.echoString( "test");
assertEquals( s, "test" );
// now call the method that invokes another bean
assertNotNull( sampleService.invokeOtherBean() );
// now make a call to the external service
String s1 = sampleService.invokeExternalService();
assertEquals(s1,"From EasyMock,got it appending new text in
SampleServiceBean" );
}
Test results or display of a sample application. String From mock is =From EasyMock,got it appending new text in SampleServiceBean
method in Sesssion Service Bean public String invokeExternalService() throws NamingException, CreateException, RemoteException {
Context ctx = new InitialContext();
ExternalServiceHome externalServiceHome =
(ExternalServiceHome)ctx.lookup( ExternalService.JNDI_NAME );
ExternalService externalService = externalServiceHome.create();
/*
* In this example we don't do anything with the the return value,
* in reality we should have some code that uses it.
*/
return (String)externalService.sampleMethod() + ",got it appending new text in SampleServiceBean";
}
[ April 06, 2006: Message edited by: poyyi sarma ]
[ April 06, 2006: Message edited by: poyyi sarma ]