【发布时间】:2011-04-11 02:52:29
【问题描述】:
我正在使用 Spring 3.0.4 和 JUnit 4.5。我的测试类目前使用 Spring 的注解测试支持,语法如下:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration (locations = { "classpath:configTest.xml" })
@TransactionConfiguration (transactionManager = "txManager", defaultRollback = true)
@Transactional
public class MyAppTest extends TestCase
{
@Autowired
@Qualifier("myAppDAO")
private IAppDao appDAO;
...
}
我真的不需要 extends TestCase 行来运行这个测试。单独运行这个测试类时不需要它。我必须添加 extends TestCase 以便可以将其添加到 TestSuite 类中:
public static Test suite() {
TestSuite suite = new TestSuite("Test for app.dao");
//$JUnit-BEGIN$
suite.addTestSuite(MyAppTest.class);
...
如果我省略 extends TestCase,我的测试套件将不会运行。 Eclipse 会将 suite.addTestSuite(MyAppTest.class) 标记为错误。
如何将 Spring 3+ 测试类添加到测试套件?我确信有更好的方法。我已经 GOOGLED 并阅读了文档。如果你不相信我,我愿意把我所有的书签都寄给你作为证据。但无论如何,我更喜欢建设性的答案。非常感谢。
【问题讨论】:
-
哈哈。我再次谷歌搜索并在谷歌搜索结果中看到了我的问题。我要重新搜索:)
-
Rod Johnson 自己写道,“Spring 本身有一个出色的单元测试套件”(theserverside.com/news/1363858/…)。这个优秀的测试套件记录在哪里?
-
你给的网址无效!
标签: spring junit testing suite