assert

Best practice for debug Asserts during Unit testing

Does heavy use of unit tests discourage the use of debug asserts? It seems like a debug assert firing in the code under test implies the unit test shouldn't exist or the debug assert shouldn't exist. "There can be only one" seems like a reasonable principle. Is this the common practice? Or do you disable your debug asserts when unit te...

Boolean Expressions in SQL Select list

I want to create a SQL Select to do a unit test in MS SQL Server 2005. The basic idea is this: select 'Test Name', foo = 'Result' from bar where baz = (some criteria) The idea being that, if the value of the "foo" column is "Result", then I'd get a value of true/1; if it isn't, I'd get false/0. Unfortunately, T-SQL doesn't like the ex...

customizing assert macro

On Windows/c++, I want to customize the assert dialog box to ignore an assertion forever, so I can be more aggressive with assertions. I understand how hard it is to write a correct assert macro, and do not wish to do this, just hook the dialog code. Is there an easy way (or concise hack) to do this? article on assert macro dangers (g...

What's the difference between Assert.AreNotEqual and Assert.AreNotSame?

In C#, what's the difference between Assert.AreNotEqual and Assert.AreNotSame ...

C++ Assertions that Can Display a Custom String with Boost or STL?

Hi, I really want to be able to go: (in C++) assert( num > 0, "The number must be greater than zero!"); In C# XNA, they have a method that does exactly this: Debug.Assert( num > 0, "The number must be greater than zero!"); Is there some way to do this so that the runtime gives me a meaning full error not just "an assertion failed" ...

How to put assert into release builds in C/C++

I need to only run ship build and I need to assert on certain condition in release build to see if the problem is fixed. How do I do it? ...

Can someone give me a good reason for why assert in php behaves the way it does?

PHP's assert statement doesn't behave like most other languages. assert('return false'); actually evaluates the string and then asserts its result (false). Instead of comparing the paramter to true, it goes through the extra step of examining the argument, and if it's a string evaluating it, then performing the comparison. Very strang...

How to find the name of the current function at runtime? (C++)

After years of using the big ugly MFC ASSERT macro, I have finally decided to ditch it and create the ultimate ASSERT macro. I am fine with getting the file and line number, and even the expression that failed. I can display a messagebox with these in, and Abort/Retry/Cancel buttons. And when I press Retry the VS debugger jumps to the ...

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 your web.config to properly use Asserts. Is this usually the best way to go or are there other methods of debugging that might be easier to u...

Is it bad practice to have more than Assert in a unit test?

Is it bad practice to have more than Assert in a unit test? Does it matter? ...

What does "#define assert(exp) ((void) 0)" do?

I came across this preprocessor definition while reading the source code in Windows Research Kernel (WRK) 1.2: #define assert(exp) ((void) 0) What does this code do? Why is it defined? ...

How does Assert.AreEqual determine equality between two generic IEnumerables?

I have a unit test that will test to see if a method that returns the correct IEnumerable. The method builds the IEnumerable using yield return. The class that it is an IEnumerable of is below: enum TokenType { NUMBER, COMMAND, ARITHMETIC, } internal class Token { public TokenType type {get; set;} public string te...

C#: How do I use Assert (Unit Testing) to verify that an exception has been thrown?

The title says it all - how do I use Assert (or other Test class?) do verify that an exception has been thrown? Thanks :) ...

How to apply "One Assertion Per Test" for OR relation condition

It's recognized that "One Assertion Per Test" in assertion. It is not good to write assertion like below: Assert((foo != null) && (bar != null)); The better chocie is: Assert(foo != null); Assert(bar != null); The question is what if the assertion is: Assert((foo == null) || (foo.length == 0)); The relationship is OR ins...

Best practice for Python Assert

Is there a performance or code maintenance issue with using assert as part of the standard code instead of using it just for debugging purposes? Is assert x >= 0, 'x is less then zero' and better or worse then if x < 0: raise Exception, 'x is less then zero' Also, is there anyway to set a business rule like if x < 0 raise err...

Literals or expressions in unit test asserts?

Do you prefer literal values or expressions in your Asserts in your unit tests? This little example demonstrates what I mean - please pay attention to the comments: [Test] public function fromXML_works() : void { var slideshow : Slideshow = SlideshowConverter.fromXML(xmlSample); // do you prefer literal value "1": assertEqu...

AssertContains on strings in jUnit

Is there a nicer way to write in jUnit String x = "foo bar"; Assert.assertTrue(x.contains("foo")); ...

Why doesn't JUnit provide assertNotEquals methods?

Does anybody know why JUnit 4 provides assertEquals(foo,bar) but not assertNotEqual(foo,bar) methods? It provides assertNotSame (corresponding to assertSame) and assertFalse (corresponding to assertTrue), so it seems strange that they didn't bother including assertNotEqual. By the way, I know that JUnit-addons provides the methods I'm...

Should we assert every object creation in java?

Sounds like a stupid question with an obvious answer :) Still I've ventured to ask just be doubly sure. We are indeed using asserts like given below ArrayList alProperties = new ArrayList(); assert alProperties != null : "alProperties is null"; Problem is that making a small & simple document to follow, on asserts is difficult. Th...

Pthread mutex assertion error

I'm encountering the following error at unpredictable times in a linux-based (arm) communications application: pthread_mutex_lock.c:82: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed. Google turns up a lot of references to that error, but little information that seems relevant to my situation. I was wondering if ...