【问题标题】:DBUnit doesn't reset sequencesDBUnit 不重置序列
【发布时间】:2011-06-10 14:16:29
【问题描述】:

我有一个带有 Spring + Maven + JPA (Hibernate) 的系统。我使用 Junit 和 DBUnit。 我有一个生成 id 的实体:在测试期间它不会重置序列。我该如何解决这个问题?

【问题讨论】:

  • 你能提供更多细节吗?为什么需要重置序列才能使您的测试成功?
  • @Filip 显然您需要重置序列才能在预期的数据集中提供静态数字。不重置序列号是动态的,这使得编写测试变得困难。

标签: java hibernate spring junit dbunit


【解决方案1】:

您可以尝试以下方法:

    @Before
    public void resetSequence() {
      // run sql to reset the sequence.
      // for DB without functionality to reset sequences (eg. oracle) you can try dropping and re-creating the sequence
    }

序列将在每次测试之前重置。

【讨论】:

    猜你喜欢
    • 2014-01-03
    • 2014-04-30
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多