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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:31:55+00:00 2026-05-28T03:31:55+00:00

How do you manage dummy data used for tests? Keep them with their respective

  • 0

How do you manage dummy data used for tests? Keep them with their respective entities? In a separate test project? Load them with a Serializer from external resources? Or just recreate them wherever needed?

We have an application stack with several modules depending on another with each containing entities. Each module has its own tests and needs dummy data to run with.

Now a module that has a lot of dependencies will need a lot of dummy data from the other modules. Those however do not publish their dummy objects because they are part of the test resources so all modules have to setup all dummy objects they need again and again.

Also: most fields in our entities are not nullable so even running transactions against the object layer requires them to contain some value, most of the time with further limitations like uniqueness, length, etc.

Is there a best practice way out of this or are all solutions compromises?


More Detail

Our stack looks something like this:

One Module:

src/main/java --> gets jared (.../entities/*.java contains the entities)
src/main/resources --> gets jared
src/test/java --> contains dummy object setup, will NOT get jared
src/test/resources --> not jared

We use Maven to handle dependencies.

module example:

  • Module A has some dummy objects
  • Module B needs its own objects AND the same as Module A

Option a)

A Test module T can hold all dummy objects and provide them in a test scope (so the loaded dependencies don’t get jared) to all tests in all Modules. Will that work? Meaning: If I load T in A and run install on A will it NOT contain references introduced by T especially not B? Then however A will know about B‘s datamodel.

Option b)

Module A provides the dummy objects somewhere in src/main/java../entities/dummy allowing B to get them while A does not know about B‘s dummy data

Option c)

Every module contains external resources which are serialized dummy objects. They can be deserialized by the test environment that needs them because it has the dependency to the module to which they belong. This will require every module to create and serialize its dummy objects though and how would one do that? If with another unit test it introduces dependencies between unit tests which should never happen or with a script it’ll be hard to debug and not flexible.

Option d)

Use a mock framework and assign the required fields manually for each test as needed. The problem here is that most fields in our entities are not nullable and thus will require setters or constructors to be called which would end us up at the start again.

What we don’t want

We don’t want to set up a static database with static data as the required objects’ structure will constantly change. A lot right now, a little later. So we want hibernate to set up all tables and columns and fill those with data at unit testing time. Also a static data base would introduce a lot of potential errors and test interdependencies.


Are my thoughts going in the right direction? What’s the best practice to deal with tests that require a lot of data? We’ll have several interdependent modules that will require objects filled with some kind of data from several other modules.


EDIT

Some more info on how we’re doing it right now in response to the second answer:

So for simplicity, we have three modules: Person, Product, Order.
Person will test some manager methods using a MockPerson object:

(in person/src/test/java🙂

public class MockPerson {

    public Person mockPerson(parameters...) {
        return mockedPerson;
    }
}

public class TestPerson() {
    @Inject
    private MockPerson mockPerson;
    public testCreate() {
        Person person = mockPerson.mockPerson(...);
        // Asserts...
    }
}

The MockPerson class will not be packaged.

The same applies for the Product Tests:

(in product/src/test/java🙂

public class MockProduct() { ... }
public class TestProduct {
    @Inject
    private MockProduct mockProduct;
    // ...
}

MockProduct is needed but will not be packaged.

Now the Order Tests will require MockPerson and MockProduct, so now we currently need to create both as well as MockOrder to test Order.

(in order/src/test/java🙂

These are duplicates and will need to be changed every time Person or Product changes

public class MockProduct() { ... }
public class MockPerson() { ... }

This is the only class that should be here:

public class MockOrder() { ... }

public class TestOrder() {
    @Inject
    private order.MockPerson mockPerson;
    @Inject
    private order.MockProduct mockProduct;
    @Inject
    private order.MockOrder mockOrder;
    public testCreate() {

        Order order = mockOrder.mockOrder(mockPerson.mockPerson(), mockProduct.mockProduct());
        // Asserts...
    }
}

The problem is, that now we have to update person.MockPerson and order.MockPerson whenever Person is changed.

Isn’t it better to just publish the Mocks with the jar so that every other test that has the dependency anyway can just call Mock.mock and get a nicely setup object? Or is this the dark side – the easy way?

  • 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-28T03:31:55+00:00Added an answer on May 28, 2026 at 3:31 am

    This may or may not apply – I’m curious to see an example of your dummy objects and the setup code related. (To get a better idea of whether it applies to your situation.) But what I’ve done in the past is not even introduce this kind of code into the tests at all. As you describe, it’s hard to produce, debug, and especially package and maintain.

    What I’ve usaully done (and AFAIKT in Java this is the best practice) is try to use the Test Data Builder pattern, as described by Nat Pryce in his Test Data Builders post.

    If you think this is somewhat relevant, check these out:

    • Does a framework like Factory Girl exist for Java?
    • make-it-easy, Nat’s framework that implements this pattern.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I manage a small group and I'd keep my work breakdown in project. However,
I manage project for JNI for both compilers: MSVC++ 8.0 and 9.0, my cpp
I manage a iPhone/Android project and one of these days my client asked me
I manage an open-source project and would like to sign the binaries that are
I manage a web application for a client with the following specs: ASP.net 3.5
I manage to identify duplicate records from two different databases: select * from taskperformance
I manage a rather large application (50k+ lines of code) by myself, and it
How would you manage the lifecycle and automated build process when some of the
I am looking to manage a SQL Server 2008 DB using Management Studio 2005.
How do you manage deploying InfoPath forms to different sharepoint servers? Is there a

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.