Reputation: 1936
A project that Im working on uses Spring and Struts.
Up until now, we we using using Struts 2.1.8.1. All my unit tests extended the StrutsSpringTestCase which in turn extended the StrutsTestCase. However, this used JUnit 3.8.2 and hence had no annotation support.
For Struts 2.2.3, the dev team added a Junit4 TestCase, called StrutsJUnit4TestCase. This test case however, does not the have the supporting functions that StrutsTestCase did e.g. for issuing struts actions. I tried to find some tutorials using this new test case, but haven't had any luck.
I should mention that I'm trying to use the Rollback annotations, to rollback the automatically rollback database changes that occur during the test.
How exactly am I supposed to use this new StrutsJunit4TestCase?
Upvotes: 3
Views: 2078
Reputation: 527
at least the following one works in my computer
public class BlaBlaBlaTestCase extends StrutsSpringTestCase {
private final Logger log = Logger.getLogger(this.getClass());
@Override
public String getContextLocations() {
return "applicationContext_test.xml";
}
@Test
public void testWhatever() {
//...
}
}
the getContextLocations method is important, because this is the method which defines where your applicationContext for testing is.
oh, i'm using junit 4.4
Upvotes: 1
Reputation: 1227
Struts2 actions are nothing but simple classes. I suggest you to test them the way you test other classes IMHO.
I've been doing this way for most of my time doing struts2 and barely felt the need to use StrutsTestCase
. If you design your actions with DI in mind you can inject any dependencies while testing the action.
Upvotes: 4