Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts testing JUnit4

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?

like image 958
Croydon Dias Avatar asked Dec 05 '25 18:12

Croydon Dias


1 Answers

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.

like image 144
doctrey Avatar answered Dec 08 '25 07:12

doctrey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!