【问题标题】:Spring JUnit4 Test Hangs after few runs几次运行后 Spring JUnit4 测试挂起
【发布时间】:2012-02-20 20:04:18
【问题描述】:

我正在使用 Spring 和 DbUnit 来测试我的 DAO。我有一个 TestExecutionListener 在每个测试类之前和之后从数据库中添加/删除数据。这是我的抽象测试类

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring/test-dao.xml"})
@TestExecutionListeners(
{ DependencyInjectionTestExecutionListener.class,CleanInsertTestExecutionListener.class}
)
@DataSetLocation("classpath:data/test-dao-dataset.xml")
public abstract class AbstractDaoTests {

我已将我的测试分组到一个套件中,当我执行该套件时,只有前几个测试运行,然后测试无限期挂起。不知道是什么原因造成的。我也没有看到任何例外。 关于可能导致它的任何想法或指示都会非常有帮助。 我能够运行单个测试,但是当我尝试在套件中运行它们时会出现问题。 另外,我正在使用 Apache Commons 池 BasicDataSource 来访问数据库。

谢谢, 贾维德

【问题讨论】:

  • 奇怪。问题出在 Apache Commons DBCP 上。出于某种奇怪的原因,连接被阻塞了。我会假设它在几次测试后就失去了连接,但仍然不明白为什么它会用完连接。

标签: spring integration-testing junit4 spring-jdbc


【解决方案1】:

发现问题。 我没有在 beforeTestClass 和 afterTestClass 方法中关闭我的 TestExecutionListeners 中的 DBUnit Connection 对象。 关闭连接解决了这个问题。

谢谢, 贾维德

【讨论】:

    猜你喜欢
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多