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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:38:06+00:00 2026-05-10T13:38:06+00:00

This past summer I was developing a basic ASP.NET/SQL Server CRUD app, and unit

  • 0

This past summer I was developing a basic ASP.NET/SQL Server CRUD app, and unit testing was one of the requirements. I ran into some trouble when I tried to test against the database. To my understanding, unit tests should be:

  • stateless
  • independent from each other
  • repeatable with the same results i.e. no persisting changes

These requirements seem to be at odds with each other when developing for a database. For example, I can’t test Insert() without making sure the rows to be inserted aren’t there yet, thus I need to call the Delete() first. But, what if they aren’t already there? Then I would need to call the Exists() function first.

My eventual solution involved very large setup functions (yuck!) and an empty test case which would run first and indicate that the setup ran without problems. This is sacrificing on the independence of the tests while maintaining their statelessness.

Another solution I found is to wrap the function calls in a transaction which can be easily rolled back, like Roy Osherove’s XtUnit. This work, but it involves another library, another dependency, and it seems a little too heavy of a solution for the problem at hand.

So, what has the SO community done when confronted with this situation?


tgmdbm said:

You typically use your favourite automated unit testing framework to perform integration tests, which is why some people get confused, but they don’t follow the same rules. You are allowed to involve the concrete implementation of many of your classes (because they’ve been unit tested). You are testing how your concrete classes interact with each other and with the database.

So if I read this correctly, there is really no way to effectively unit-test a Data Access Layer. Or, would a ‘unit test’ of a Data Access Layer involve testing, say, the SQL/commands generated by the classes, independent of actual interaction with the database?

  • 1 1 Answer
  • 1 View
  • 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-10T13:38:07+00:00Added an answer on May 10, 2026 at 1:38 pm

    There’s no real way to unit test a database other than asserting that the tables exist, contain the expected columns, and have the appropriate constraints. But that’s usually not really worth doing.

    You don’t typically unit test the database. You usually involve the database in integration tests.

    You typically use your favourite automated unit testing framework to perform integration tests, which is why some people get confused, but they don’t follow the same rules. You are allowed to involve the concrete implementation of many of your classes (because they’ve been unit tested). You are testing how your concrete classes interact with each other and with the database.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would favor saving your state to a database if… May 12, 2026 at 3:46 pm
  • Editorial Team
    Editorial Team added an answer It is about as accurate as you can get for… May 12, 2026 at 3:46 pm
  • Editorial Team
    Editorial Team added an answer Try For Each dr As DataRow In ds.Tables("records").Rows file =… May 12, 2026 at 3:46 pm

Related Questions

Hey. I'm taking a course titled Principles of Programming Languages, and I need to
As I think most people know already, or if you don't, FPDF released a
I'm running an SQL query against a mainframe DB2 database using the OdbcDataReader class
We currently have an inventory management system that was built in-house. It works great,

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.