Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 86529

Pages: 1
JavaWorld
addict


Reged: 06/20/03
Posts: 482
Unit test Struts applications
      #40375 - 11/09/06 12:42 PM

Unit test Struts applications

Post Extras: Print Post   Remind Me!   Notify Moderator  
KSader
Unregistered




Re: Unit test Struts applications [Re: JavaWorld]
      #40417 - 11/10/06 09:38 AM

I'm surprised you didn't mention JMock for testing struts actions. I've personally found it easier to use than AOP.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Ramnivas Laddad
Unregistered




Re: Unit test Struts applications [Re: KSader]
      #40421 - 11/10/06 10:47 AM

The problem dealt in this article is not EasyMock vs. JMock vs. AOP. Rather, it is how to inject your mock objects appropriately.

The core idea in the article is leveraging AOP with *a* mock framework to simplify testing; whether you use EasyMock or JMock or hand-written mock is fundamentally inconsequential here.

Good article, BTW.

-Ramnivas


Post Extras: Print Post   Remind Me!   Notify Moderator  
Andres Almiray
Unregistered




Re: Unit test Struts applications [Re: Ramnivas Laddad]
      #40425 - 11/10/06 11:57 AM

I agree with Ramnivas that the goal of the article is to show a new way for testing Struts applications.

Dwelving deeper into the implementation details, StrutsTestCase and Spring enabled test cases will help you get a reference to the Action for mock injection.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Walter Jia
Unregistered




Re: Why not JMock [Re: Ramnivas Laddad]
      #40528 - 11/13/06 09:16 PM

Thanks to Ramnivas for pointing out the core idea of the article.

The presented AOP solution applies to the integration of JMock and StrutsTestCase as well. Unlike EasyMock, JMock requires test cases to derive from its base class. This brings up the challenge of simulating multiple inheritance in Java, since StrutsTestCase is also inheritance based. The simulation is achievable by combining inheritance and composition. To keep the article focused on the role of AOP, I chose EasyMock over JMock for the discussion.

Walter


Post Extras: Print Post   Remind Me!   Notify Moderator  

Unregistered




Re: Unit test Struts applications [Re: JavaWorld]
      #55103 - 10/03/07 12:33 PM

Hi,

I am posting the test class and the error I got while unit testing the struts application with easy mock.

Please, let me know if any one has a solution for the following error:

java.lang.IllegalStateException: incompatible return value type.

at
controller.setReturnValue("Great");


code :
------

package com.unittest;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import org.easymock.MockControl;
import com.jamesholmes.minihr.*;
public class EmployeeSearchServiceTest extends TestCase {

protected void setUp() throws Exception {
super.setUp();
}

protected void tearDown() throws Exception {
super.tearDown();
}

//Test searchByName() method in EmployeeSearchService class
public void testSearchByName() {
//define the mock object
MockControl controller = MockControl.
createControl(EmployeeSearchServiceIntf.class);
final EmployeeSearchServiceIntf inf = (EmployeeSearchServiceIntf)
controller.getMock();

// ArrayList myArr = new ArrayList();
//define the behavior of mock object
inf.searchByName("Mary Williams");
controller.setReturnValue("Great");
controller.replay();

//use override technology to bridge from
//mock object to the class to be tested
EmployeeSearchService instance = new EmployeeSearchService() {
protected EmployeeSearchServiceIntf getEmployeeSearchServiceIntf() {
return inf;
}
};


//start test
ArrayList result = instance.searchByName("Mary Williams");

//do verification between expected result
//and actual result
assertEquals("Woo!Great", result);

//do verification on the mock object
controller.verify();
}
}



Error:
-------

java.lang.IllegalStateException: incompatible return value type
at org.easymock.internal.MocksControl.andReturn(MocksControl.java:90)
at org.easymock.MockControl.setReturnValue(MockControl.java:162)
at com.bofa.unittest.EmployeeSearchServiceTest.testSearchByName(EmployeeSearchServiceTest.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 8135

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5