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

  • Home
  • SEARCH
  • 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 6220389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:56:55+00:00 2026-05-24T07:56:55+00:00

I have some test classes that are making use of spring-batch, and hibernate. My

  • 0

I have some test classes that are making use of spring-batch, and hibernate. My test contexts establish an h2 in memory database, initialized the hibernate session factory, which creates most of the db schema, and also executes some specific SQL scripts to set up the database schema objects required for spring batch (non-orm). Hibernate does a very nice job only doing what is necessary, however the spring-batch initialization scripts are not as smart.

My test configuration uses an h2 embedded database, so I can safely initialize everything once, however, I need to convey to spring to only initialize the rest integration infrastructure (e.g hbm session factory, and spring-batch schemas) once for the whole collection of tests being run.

My unit tests all run individually, but tests 2 through N fail when testing the whole package as they are performing the same db schema initialization repeatedly, and dying on (db) object already exists errors.

I am looking to initialize an application context for the whole collection of integration tests, and then delegate configuration of the details for a specific test to the MyTest-context, yet still initialize the main application context when running a single integration test.

I have a common set of spring configuration files which are imported into test context to initialize the infrastructure needed to tests application services. The problem comes from running all tests in a package, etc. The test system calls the same initialization multiple times.

I am hoping this is a pretty common problem and that I overlooked a detail in spring or JUnit’s documentation.

  • 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-24T07:56:56+00:00Added an answer on May 24, 2026 at 7:56 am
    1. By default, Spring caches ApplicationContext instances that are loaded for tests. The only reasons that it would init a new one are that a test uses a different set of context files and hence needs a different context or a test makes use of the @DirtiesContext annotation.
    2. Why not just add an “if not exists” to your sql scripts?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to testing.I have to test some C# classes.Kindly let me know
I have some classes(call it Class A) which I would like to unit test
If I have some php classes inside a namespace com\test and want to import
I have some code that attempts to test whether my application is running with
I have some test case classes organized in directories foo_tests foo_tests1.py foo_tests2.py ... bar_tests
I am trying to test some classes that rely on a Task to do
My development team has started to use Mockito and have classes that have been
I'm trying to test some DAO Classes that inherit from a Generic one, and
I have some packages com.company.testing.module1 com.company.testing.module2 com.company.testing.module3 I also have some classes that have
I have a grails 1.3.7 application. I am making use of Spring's JMS classses

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.