Linked Questions
10 questions linked to/from When should I use Debug.Assert()?
205 votes
17 answers
86k views
When should assertions stay in production code? [closed]
There's a discussion going on over at comp.lang.c++.moderated about whether or not assertions, which in C++ only exist in debug builds by default, should be kept in production code or not. Obviously, ...
199 votes
9 answers
237k views
C# - What does the Assert() method do? Is it still useful?
I am debugging with breakpoints and I realize the assert call? I thought it was only for unit tests. What does it do more than breakpoint? Since I can breakpoint, why should I use Assert?
111 votes
8 answers
24k views
Debug.Assert vs Exception Throwing
I've read plenty of articles (and a couple of other similar questions that were posted on StackOverflow) about how and when to use assertions, and I understood them well. But still, I don't understand ...
45 votes
2 answers
12k views
Debug.Assert vs Code Contract usage
When should I debug.assert over code contracts or vice versa? I want to check precondition for a method and I am confused to choose one over the other. I have unit tests where I want to test failure ...
22 votes
5 answers
4k views
Which exception to throw when an invalid code path has been taken?
I find myself writing some methods where there is a code path that should never happen. Here is a simplified example: double Foo(double x) { int maxInput = 100000; double castMaxInput = (...
10 votes
5 answers
2k views
Does Unit Testing make Debug.Assert() unnecessary?
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()...
15 votes
2 answers
4k views
Is it worth using Debug.Assert in ASP.NET?
It seems like a fairly large hassle to set up a proper debug environment in ASP.NET and I'm just wondering if using Asserts are the way to go or not. I've read a bit and saw that you need to modify ...
2 votes
2 answers
849 views
Assertions C# + When to use them
I have seen couple of posts regarding usage of Debug.Assert in C#. But I still have one doubt, may be its repeated, but I need to ask. Is there a strict rule that Debug.Assert should be used only for ...
1 vote
2 answers
7k views
Using Asserts outside of Unit-Test
We're in a process of writing Test framework (for Integration Testings) and I have a question regarding asserts. The test code looks like that: public class MyTestClass { [Fact] public void ...
1 vote
3 answers
175 views
A set of methods for checking arguments in nested static class
I have a static class ArgumentHelper which can check for example: ArgumentHelper.NotNull(instance, "instance"). But it works for some standard built-in .net framework classes, if I implement my own ...