Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 592997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:47:55+00:00 2026-05-13T15:47:55+00:00

I am using DbUnit together with Unitils, which works great most of the time.

  • 0

I am using DbUnit together with Unitils, which works great most of the time.

Today I found a strange problem.

Situation is:

  • I use Hibernate, and have id with “increment” generator:
<id name="Id">
   <generator class="increment"/>
</id>
  • I prepare test dataset, where maximal id is 5.
  • I use clean-insert loading strategy.
  • I have two test methods test1 and test2, each adding one row in this table.
  • After test1 method newly added row has id=6.
  • After test2 method newly created row has id=7.

This is all OK and I get why this is like that. It is a problem from maintenance perspective though. If I ever add third test method between the two, method test2 will suddenly fail even though nothing changed, just because row will get different id.

Is there anyway I can force DbUnit or Hibernate to calculate next id value before each test method?

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:47:55+00:00Added an answer on May 13, 2026 at 3:47 pm

    First thing, you should provide the complete dataset, yes with id as well. If not, don’t test or base your test upon ids. Why not test? because its already well tested and reliable thing. Always remember never test third party libraries, most of them already well tested. But it seems quite impossible to not depending upon ids. I agree, you should write some mock class to tackle this issue for you, or may be you can provide some setter method to overwrite the value generated by your own.

    Second option is always start your test case with empty table. You can write a fixture to clean the table for you, before every test case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would appreciate some help with using dbunit. I use postgresql9 as db. I
I am trying to get scala specs and unitils-dbunit to work. To use unitils
I am using dbunit to create database backups, which can be imported and exported.
I'm using DBUnit for testing DAOs implemented with Hibernate and Spring. I put a
Using CI for the first time and i'm smashing my head with this seemingly
Using import datetime in python, is it possible to take a formatted time/date string
I've just been using DBUnit for the last 2 days and I got a
I wrote a simple tool to generate a DBUnit XML dataset using queries that
We have a pretty mature COM dll, which we test using DUnit. One of
Using PyObjC , you can use Python to write Cocoa applications for OS X.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.