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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:12:34+00:00 2026-05-11T17:12:34+00:00

Its been a while I have ready Mcconnell’s Code Complete . Now I read

  • 0

Its been a while I have ready Mcconnell’s “Code Complete“. Now I read it again in Hunt & Thomas’ “The Pragmatic Programmer“: Use assertions! Note: Not Unit Testing assertions, I mean Debug.Assert().

Following the SO questions When should I use Debug.Assert()? and When to use assertion over exceptions in domain classes assertions are useful for development, because “impossible” situations can be found quite fast. And it seems that they are commonly used. As far as I understood assertions, in C# they are often used for checking input variables for “impossible” values.

To keep unit tests concise and isolated as much as possible, I do feed classes and methods with nulls and “impossible” dummy input (like an empty string).

Such tests are explicitly documenting, that they don’t rely on some specific input. Note: I am practicing what Meszaros’ “xUnit Test Patterns” is describing as Minimal Fixture.

And that’s the point: If I would have an assertions guarding these inputs, they would blow up my unit tests.

I like the idea of Assertative Programming, but on the other hand I don’t need to force it. Currently I can’t think of any use for Debug.Assert(). Maybe there is something I miss? Do you have any suggestions, where they could be really useful? Maybe I just overestimate the usefulness of assertions? Or maybe my way of testing needs to be revisited?

Edit: Best practice for debug Asserts during Unit testing is very similar, but it does not answer the question which bothers me: Should I care about Debug.Assert() in C# if I test like I have described? If yes, in which situation are they really useful? In my current point of view such Unit Tests would make Debug.Assert() unnecessary.

Another point: If you really think that, this is a duplicate question, just post some comment.

  • 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-11T17:12:34+00:00Added an answer on May 11, 2026 at 5:12 pm

    In theory, you’re right – exhaustive testing makes asserts redundant. In theory. In parctice, they’re still useful for debugging your tests, and for catching attempts by future developers who might try to use interfaces not according to their intended semantics.

    In short, they just serve a different purpose from unit tests. They’re there to catch mistakes that by their very nature aren’t going to be made when writing unit tests.

    I would recommend keeping them, since they offer another level of protection from programmer mistakes.

    They’re also a local error protection mechanism, whereas unit tests are external to the code being tested. It’s far easier to “inadvertently” disable unit tests when under pressure than it is to disable all the assertions and runtime checks in a piece of code.

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

Sidebar

Ask A Question

Stats

  • Questions 164k
  • Answers 164k
  • 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
  • Editorial Team
    Editorial Team added an answer What if "default.aspx" looked at the useragent and sent a… May 12, 2026 at 12:24 pm
  • Editorial Team
    Editorial Team added an answer This is NOT ok as is. You should use a… May 12, 2026 at 12:24 pm
  • Editorial Team
    Editorial Team added an answer Just iterate over the elements. Like this: for (int i… May 12, 2026 at 12:24 pm

Related Questions

Its been a while I have ready Mcconnell's Code Complete . Now I read
I've been looking into improving SQLite performance for my site, especially with regard to
I'm considering using PostgreSQL's Ltree module in my application to help with threaded comments.
Ok, it's been a while since I've worked with classic asp so I'm a
I've got a thread that's polling a piece of hardware. while not hardware_is_ready(): pass

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.