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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:32:26+00:00 2026-05-11T15:32:26+00:00

I’m writing unit-tests for an app that uses a database, and I’d like to

  • 0

I’m writing unit-tests for an app that uses a database, and I’d like to be able to run the app against some sample/test data – but I’m not sure of the best way to setup the initial test data for the tests.

What I’m looking for is a means to run the code-under-test against the same database (or schematically identical) that I currently use while debugging – and before each test, I’d like to ensure that the database is reset to a clean slate prior to inserting the test data.

I realize that using an IRepository pattern would allow me to remove the complexity of testing against an actual database, but I’m not sure that will be possible in my case.

Any suggestions or articles that could point me in the right direction?

Thanks!

–EDIT–

Thanks everyone, those are some great suggestions! I’ll probably go the route of mocking my data access layer, combined with some simple set-up classes to generate exactly the data I need per test.

  • 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-11T15:32:26+00:00Added an answer on May 11, 2026 at 3:32 pm

    Here’s the general approach I try to use. I conceive of tests at about three or four levels:: unit-tests, interaction tests, integration tests, acceptance tests.

    At the unit test level, it’s just code. Any database interaction is mocked out, either manually or using one of the popular frameworks, so loading data is not an issue. They run quick, and make sure the objects work as expected. This allows for very quick write-test/write code/run test cycles. The mock objects serve up the data that is needed by each test.

    Interaction tests test the interactions of non-trivial class interactions. Again, no database required, it’s mocked out.

    Now at the integration level, I’m testing integration of components, and that’s where real databases, queues, services, yada yada, get thrown in. If I can, I’ll use one of the popular in-memory databases, so initialization is not an issue. It always starts off empty, and I use utility classes to scrub the database and load exactly the data I want before each test, so that there’s no coupling between the tests.

    The problem I’ve hit using in-memory databases is that they often don’t support all the features I need. For example, perhaps I require an outer join, and the in-memory DB doesn’t support that. In that case, I’ll typically test against a local conventional database such as MySQL, again, scrubbing it before each test. Since the app is deployed to production in a separate environment, that data is untouched by the testing cycle.

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

Sidebar

Related Questions

No related questions found

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.