我正在做的一个项目使用 Spring 和 Struts。
到目前为止,我们使用的是Struts 2.1.8.1。我所有的单元测试都扩展了 StrutsSpringTestCase 又扩展了 StrutsTestCase。但是,它使用 JUnit 3.8.2,因此没有注释支持。
对于 Struts 2.2.3,开发团队 添加了一个 Junit4 TestCase,名为 StrutsJUnit4TestCase。然而,这个测试用例不具有 StrutsTestCase 确实用于发出 struts 操作。我试图找到一些使用这个新测试用例的教程,但没有任何运气。
我应该提到,我正在尝试使用回滚注释来回滚测试期间发生的自动回滚数据库更改。
我究竟应该如何使用这个新的 StrutsJunit4TestCase?
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?
发布评论
评论(2)
Struts2 动作只不过是简单的类。我建议您像测试其他课程一样测试它们。恕我直言。
我在 struts2 的大部分时间里都是这样做的,几乎感觉不到需要使用
StrutsTestCase
。如果您在设计操作时考虑到 DI,则可以在测试操作时注入任何依赖项。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.至少下面的方法在我的计算机上有效
getContextLocations 方法很重要,因为这是定义用于测试的 applicationContext 所在位置的方法。
哦,我正在使用junit 4.4
at least the following one works in my computer
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