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 1110479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:24:09+00:00 2026-05-17T02:24:09+00:00

I am new to automated testing and dbUnit. So I would appreciate your advice.

  • 0

I am new to automated testing and dbUnit. So I would appreciate your advice.

I am going to create a test suite, that will run the following way:

  • create an in-memory H2 database
  • run DDL scripts to create tables
  • run dbUnit to insert initial data (let’s call it STATE0) that will be used by all tests.
  • run tests

Till there it looks nice for me, but what I don’t understand, is how do I revert the database to the STATE0 after a test run and changed the data?

Can I do it with dbUnit?
Or with something else?
Should I recreate the database before each test?

Simple not commiting transactions in tests is not appropriate for me, because the tests will eventually run more than one transaction over may be more than one database connection.

  • 1 1 Answer
  • 0 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-17T02:24:10+00:00Added an answer on May 17, 2026 at 2:24 am

    DBUnit can do the work four you automatically if you write your @BeforeClass, @Before and @After methods properly. E.g. in our project, using Derby, one such test case looks like

    public class MyTest {
        protected static IDataSet getDataSet() throws Exception {
            URL url = MyTest.class.getClassLoader().getResource("MyDataSet.xml");
            return new XmlDataSet(new FileInputStream(url.getPath()));
        }
    
        private static JdbcDatabaseTester databaseTester;
    
        @BeforeClass
        public static void setUpClass() throws Exception {
            // Init test environment, session etc.
            databaseTester = new JdbcDatabaseTester(
                    "org.apache.derby.jdbc.ClientDriver",
                    "jdbc:derby://localhost:1527/myschema", 
                    "username", "password");
            databaseTester.setDataSet(getDataSet());
        }
    
        @AfterClass
        public static void tearDownClass() {
            // Close session etc.
        }
    
        @Before
        public void setUp() throws Exception {
            databaseTester.onSetup();
        }
    
        @After
        public void tearDown() throws Exception {
            databaseTester.onTearDown();
        }
    
        @Test
        public void test() throws Exception { ... }
    }
    

    This code puts back (a subset of) the DB schema to the state defined by MyDataSet.xml after each test. (Note that, as @Pascal commented, the reset may not always be full – if a test modifies a table which is not in the dataset, it won’t be affected by the @Before / @After methods.)

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

Sidebar

Related Questions

We write a lot of JavaScript code to run our automated testing using a
I am new to automated web testing and I am currently migrating from an
I am pretty new to NUnit (and automated testing in general). I have recently
I'm writing an automated test framework where after each action (loading a new page
I'm new to selenium testing and am trying to get my first test up
I'm fairly new at Python/JS and also automated testing with Selenium/WebDriver, but I have
I have successfully automated the process of creating a new IIS website, however the
I am developing automated testing tool type application in which it get window handle
Use case: Fitnesse is used for automated testing of the web site. SUT (software
I am writing an application that responds to keyboard actions. To automate testing, I

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.