aspose file tools *
The moose likes Testing and the fly likes help with testing framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "help with testing framework" Watch "help with testing framework" New topic
Author

help with testing framework

poyyi sarma
Greenhorn

Joined: Apr 05, 2006
Posts: 2
I'm trying to come up with testing framework for business app.
As i'm newbie in testing frameworks,can any one help with their suggession how to use easymock & cacuts for coming up with a framework

current design looks like this

JsP---->(1*)Client---->(2*)StatelessServiceBean1---->(3*)command---->(4*)Action-->(5*)remoteStatelessbean

1*Client
custinfo
validateCutomer(custoinfo+infofromjsp){

mehtodInSessionBean1(custoinfo+infofromjsp){
}

}

public static void main(String arg[]){
populate "cusomerinfo" per jsp input
}


2*StatelessServiceBean
ejbcreate(){

get reference to another remote statlessSessionbean2 = Home.create()
this reference passed till ActionClass whose remote and home interface is only available
we just use it as service, we have no control on it
}

methodInSessionBean1(custoinfo){
//call method in command
methodInCommand(custinfo,statlessSessionbean2)
}


3*Command

methodInCommand(custinfo,statlessSessionbean2){
validate the custominfo

//call method in action passes the sessionBean2
methodInAction(validatedCustoInfo,sessionBean2)

}


4*Action

MethodInAction(validatedCustoInfo,sessionBean2){
builds custoinfo xml and calls makes the remote ejb thru the reference passed
sessionBean2.process(xmldoc.text)--which update the tables

}

I would like to have end to end testing from client to sessionbean2(remote).

using easymock i was able to mock the remoteSession sessionBean2,but if i have to end-end testing
how should mock both client and external sesssion bean at the same time and test and also how can handle exception thrown to various levels.

any help in this regard greatly appreciated
Mattias Arthursson
Ranch Hand

Joined: Jul 26, 2004
Posts: 90
Originally posted by poyyi sarma:

I would like to have end to end testing from client to sessionbean2(remote).

using easymock i was able to mock the remoteSession sessionBean2,but if i have to end-end testing
how should mock both client and external sesssion bean at the same time and test and also how can handle exception thrown to various levels.

any help in this regard greatly appreciated


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).


Admit nothing. Blame everyone. Be bitter.
poyyi sarma
Greenhorn

Joined: Apr 05, 2006
Posts: 2
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with testing framework