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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:23:40+00:00 2026-06-15T03:23:40+00:00

Usually in unit testing, mocking of objects is used; but how should one write

  • 0

Usually in unit testing, mocking of objects is used; but how should one write unit tests for a JPA Entity for example if the EntityManager is mocked? What is actually tested?

Edit: Suppose I want to test if an object is well persisted; in production code, for persistence, a container-provided EntityManager is available. For this type of tests should this EntityManager be mocked, should it be a resource-local one for tests or should the tests be ran in the container (test running be triggered from Java code)?

  • 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-06-15T03:23:41+00:00Added an answer on June 15, 2026 at 3:23 am

    An entity represents data. It can have some methods (other than getters and setters) that can be unit-tested as any other method.

    If you want to test that the entity can be persisted and retrieved from the database (i.e. that its mapping is defined correctly), then you shouldn’t mock anything. Have a test that uses a real entity manager and a database filled with test data, and that tries to persist and/or retrieve an instance of your entity.

    You could use DbSetup (yes, self-promotion here) to fill the database with test data before such tests.

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

Sidebar

Related Questions

I have a factory method that creates objects to be used in unit tests.
When one starts searching for PHP unit tests, one usually stumbles upon: PHPUnit. SimpleTest.
So with most unit testing utilities I have come across, you usually get access
I am unit testing domain logic and domain objects backed by a neo4j database.
How do you usually go about separating your codebase and associated unit tests ?
To be able to unit test my C++ code I usually pass the constructor
I have a class in a unit. Usually, when I changed the algorithm of
I have a unit test project based on UnitTest++. I usually put a breakpoint
Usually I worked with PostgreSQL and never had a problem, but now I need
Usually I prefer to write my own solutions for trivial problems because generally plugins

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.