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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:59:40+00:00 2026-05-10T17:59:40+00:00

I work with a lot of web applications that are driven by databases of

  • 0

I work with a lot of web applications that are driven by databases of varying complexity on the backend. Typically, there’s an ORM layer separate from the business and presentation logic. This makes unit-testing the business logic fairly straightforward; things can be implemented in discrete modules and any data needed for the test can be faked through object mocking.

But testing the ORM and database itself has always been fraught with problems and compromises.

Over the years, I have tried a few strategies, none of which completely satisfied me.

  • Load a test database with known data. Run tests against the ORM and confirm that the right data comes back. The disadvantage here is that your test DB has to keep up with any schema changes in the application database, and might get out of sync. It also relies on artificial data, and may not expose bugs that occur due to stupid user input. Finally, if the test database is small, it won’t reveal inefficiencies like a missing index. (OK, that last one isn’t really what unit testing should be used for, but it doesn’t hurt.)

  • Load a copy of the production database and test against that. The problem here is that you may have no idea what’s in the production DB at any given time; your tests may need to be rewritten if data changes over time.

Some people have pointed out that both of these strategies rely on specific data, and a unit test should test only functionality. To that end, I’ve seen suggested:

  • Use a mock database server, and check only that the ORM is sending the correct queries in response to a given method call.

What strategies have you used for testing database-driven applications, if any? What has worked the best for you?

  • 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. 2026-05-10T17:59:40+00:00Added an answer on May 10, 2026 at 5:59 pm

    I’ve actually used your first approach with quite some success, but in slightly different ways that I think would solve some of your problems:

    1. Keep the entire schema and scripts for creating it in source control so that anyone can create the current database schema after a check out. In addition, keep sample data in data files that get loaded by part of the build process. As you discover data that causes errors, add it to your sample data to check that errors don’t re-emerge.

    2. Use a continuous integration server to build the database schema, load the sample data, and run tests. This is how we keep our test database in sync (rebuilding it at every test run). Though this requires that the CI server have access and ownership of its own dedicated database instance, I say that having our db schema built 3 times a day has dramatically helped find errors that probably would not have been found until just before delivery (if not later). I can’t say that I rebuild the schema before every commit. Does anybody? With this approach you won’t have to (well maybe we should, but it’s not a big deal if someone forgets).

    3. For my group, user input is done at the application level (not db) so this is tested via standard unit tests.

    Loading Production Database Copy:
    This was the approach that was used at my last job. It was a huge pain because of a couple of issues:

    1. The copy would get out of date from the production version
    2. Changes would be made to the copy’s schema and wouldn’t get propagated to the production systems. At this point we’d have diverging schemas. Not fun.

    Mocking Database Server:
    We also do this at my current job. After every commit we execute unit tests against the application code that have mock db accessors injected. Then three times a day we execute the full db build described above. I definitely recommend both approaches.

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

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The only reliable way to do this would be to… May 11, 2026 at 12:16 pm
  • added an answer The only reliable way I got this to work for… May 11, 2026 at 12:16 pm
  • added an answer <ContextMenu> <ContextMenu.Resources> <Style TargetType='{x:Type MenuItem}'> <!--Setters--> </Style> </ContextMenu.Resources> <MenuItem/> <!--Other… May 11, 2026 at 12:16 pm

Related Questions

I work with a lot of web applications that are driven by databases of
I work with a lot of offsite developers and contractors. I ask them daily
I work a lot with serial communications with a variety of devices, and so
A few years ago I did a lot of work with CGI.pm. I'm evaluating
I am working with legacy systems at the moment, and a lot of work
I work a lot with network and serial communications software, so it is often
I work a lot with decision makers looking to use technology better in their
I work a lot with external Web Services, and I need to create an
Grasping at straws here... I work with a VB6 desktop system using several 2003-style
I have a situation where I need to work with a datagrid and adding

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.