3

I annotate my test methods like this:

@Test
@DatabaseSetup("/default_database_data.xml")
@ExpectedDatabase(value = "/expected_database_1.xml", assertionMode = NON_STRICT)

is it possible to manually perform the things that @DatabaseSetup and @ExpectedDatabase does:

@Test
public void test(){
  // DBUnit.setup("/default_database_data.xml");
  dao.insert(...);
  // DBUnit.expected("/expected_database_1.xml");
}

I made the syntax up, just to give you an idea of what I need: perform 2 setups and assertions in one unit test.

7
  • why would you want to do two setups? Can you plz explain? Commented Apr 23, 2013 at 7:09
  • DBUnit doesn't clean auto-generated IDs (sequences). In my expected sets I have tables with those IDs (and foreign keys pointing to those IDs). If the sequeces are not cleared, then the order of tests dictates the IDs of rows. So either I order the tests or clear the sequences or test foreign keys somehow different.. I don't know about any such solution, so I planned to have 1 test which calls non-test methods containing actual .. test code. Between the calls I need to reset & load DB. Commented Apr 23, 2013 at 7:50
  • 2
    two things that might work, check this link. stackoverflow.com/questions/3813684/…. And also this annotation: @DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD) on the class. Commented Apr 23, 2013 at 7:57
  • @DitirtiesContext seems to make my tests run in order.. could this be true? Commented Apr 23, 2013 at 8:09
  • not really. I just clears the application context. Read the documentation on it. Commented Apr 23, 2013 at 8:12

1 Answer 1

1

two things that might work, check this link.

Link

And also this annotation:

  @DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
Sign up to request clarification or add additional context in comments.

2 Comments

I just need to confirm if this actually works.. everywhere. And I'll accept :)
I can't confirm this, but generally seems to work. This is not a good solution, so, dear visitors, pay attention when using this :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.