assertions

When should I use Debug.Assert()?

I've been a professional software engineer for about a year now, having graduated with a CS degree. I've known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET at all until recently. Our production code contains no asserts whatsoever and my question is this... Should I begin using Asserts in our pr...

Rhino Mocks: Asserting that a method is called exactly one time

I want to assert that a method is called exactly one time. Update: I'm using RhinoMocks 3.5. Here's what I thought would work: [Test] public void just_once() { var key = "id_of_something"; var source = MockRepository.GenerateStub<ISomeDataSource>(); source.Expect(x => x.GetSomethingThatTakesALotOfResources(key)) ...

Java assertions underused

Hi, I'm wondering why the "assert" keyword is so underused in Java? I've almost never seen them used, but I think they're a great idea. I certainly much prefer the brevity of: assert (param != null : "Param cannot be null"); to the verbosity of: if (param == null) { throw new IllegalArgumentException("Param cannot be null"); } ...

SAML Assertion WriteXML issue in C#

I've created an instance of a SamlAssertion, and added the the authorization statement and attribute statments to it, and now I want to print out the XML so I can do an HTTP post, but not all of the assertion is being outputed. What am I missing (I'm sure it's something bone-headed)? Here is the code I'm using: // Add the Statements t...

How did you extend your Assert class

I love to Extend my Assert.AreEqual to many different classes, the known one is the CollectionAssert of course, but I can think of some more such as: ImageAssert, XmlAssert etc.. Did you Create your own Assert classes? and what kind of new would you like to create? ...

Are assertions always bad?

I used to work for a company where some of the lead architect/developers had mandated on various projects that assertions were not to be used, and they would routinely be removed from code and replaced with exceptions. I feel they are extremely important in writing correct code. Can anyone suggest how such a mandate could be justified?...

Debug.Assert vs Exceptions

Surprisingly I was only able to find one previous question on SO about this subject, and I'd just like to get the community "Vote of Confidence" (or not!) on my approach. The way I see it is thus: use Debug.Assert to state things you EXPECT would be true. This would be used when we are in complete control over our environment, for ex...

How to debug a "debug assertion failure" in VC++ 6

I wonder how to debug the following error: Debug Assertion failure Program: tomtoprog.exe File: dbgheap.c Line: 1044 Expression:_CrtIsValidHeapPointer(pUserData) ... I'm quiet new to windows development with VC++ 6 ... is there a valgrind or something like that? The tomtoprog code is not written by me and its rather messy ... so som...

List of all PHPUnit assertions

Where can I find a list of all PHPUnit assertions? ...

What makes the CLR show Assertions?

If I define the Debug constant for my C# Project in visual studio I can be sure that assertions will be evaluated and a messagebox is shown when they fail. But what flag, attribute makes the CLR at runtime actually decide whether a an assertion is evaluated and displayed. Does the assertion code not end up in the IL when DEBUG is define...

Why is there no assertError() function in FlexUnit?

It seems that most XUnit testing frameworks provide assertions for the times when you want to assert that a given operation will thrown an exception (or an Error in AS3 parlance.) Is there some "standard" way of doing this that I am overlooking, which would explain the absence of an assertError() assertion included with FlexUnit? I kno...

Smalltalk and Assertions

Tryng out some smalltalk + TDD + "good practices" I've run into a kinda ugly block: How do I do an assertion in GNU Smalltalk? I'm just looking for a simple ifFalse: [Die] kind of thing ...

Assertion in VS2008 but not in VS2005

Hello, After switching from VS2005 to VS2008 SP1, I found an issue that I can't explain. A program works fine under VS2005 in both release and debug mode. Under VS2008, when entering the debugger an assert is raised. If I let the program run (in debug or release mode), no assertion at all. I spent almost two days on this and I don't un...

Assert.ReferenceEquals() Passes where Object.ReferenceEquals() returns 'false' in Visual Studio Test

In attempting to create an initial, failing unit test in Visual Studio Professonal 2008's test capabilities, I can't seem to get Assert.ReferenceEquals() to correctly fail when an object instance is not equal to a null reference. Note that object.ReferenceEquals() is correctly returning false for this same comparison. Here is my class c...

Is Belt and Braces programming good practice or just introducing needless complexity?

I was wondering whether using a Belt and Braces (Suspenders) approach to programming - and to data validation in particular - was good practice or not. This came about from the following example. I was creating a form and I added Listeners to all the fields which should mean that the OK button is only enabled if all the fields in the f...

Avoiding unused variables warnings when using assert() in a Release build

Sometimes a local variable is used for the sole purpose of checking it in an assert(), like so - int Result = Func(); assert( Result == 1 ); When compiling code in a Release build, assert()s are usually disabled, so this code may produce a warning about Result being set but never read. A possible workaround is - int Result = Func();...

Benefits of Assertive Programming

What is the point of putting asserts into our code ? What are the benefits of assertive programming ? private void WriteMessage(string message) { Debug.Assert(message != null, "message is null"); File.WriteAllText(FILE_PATH, message); } For example we can check the message variable and throw an exception here. Why do I use as...

C compiler asserts - how to implement?

I'd like to implement an "assert" that prevents compilation, rather than failing at runtime, in the error case. I currently have one defined like this, which works great, but which increases the size of the binaries. #define MY_COMPILER_ASSERT(EXPRESSION) switch (0) {case 0: case (EXPRESSION):;} Sample code (which fails to compile). ...

Implementing assertions in Progress 4GL

What is the best way of implementing assertions using Progress 4GL or WebSpeed? ...

Why is my vector code asserting? What is an assert anyway?

What exactly is an "assert", or more specifically, how do I get rid of an error. When I create a vector of pointers to a class with data member int x, and then do this: for(I=antiviral_data.begin();I<antiviral_data.end();I++) { if((*I)->x>maxx) { antiviral_data.erase(I); } } And run the program, I get no errors until...