﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Matthew Wills commented on Got to debug is a bug, fix your error messages</title><description>Gian,

&gt;&gt; I agree with matthew that an Assert.IsNull is a clearer form of assertion, but the key point is including the real error message in the unit test result to have a quick hint of why the test is failing.

Assert.IsNull(message, message) would do this (the second parameter being the failed assertion message).

&gt;&gt; It will throw an exception if x.Severity is null.

I don't think any of the proposed solutions will do that. They may have issues if backupStatus.Messages was null, or contained a null entry, though.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment14</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment14</guid><pubDate>Fri, 06 Apr 2012 22:26:31 GMT</pubDate></item><item><title>Lookman commented on Got to debug is a bug, fix your error messages</title><description>It will throw an exception if x.Severity is null.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment13</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment13</guid><pubDate>Thu, 05 Apr 2012 21:02:49 GMT</pubDate></item><item><title>Gian Maria commented on Got to debug is a bug, fix your error messages</title><description>When a unit test fails the name of the unit test is important, but if you have some more descriptive failure message it will help you finding the real cause of the test failure.

I agree with matthew that an Assert.IsNull is a clearer form of assertion, but  the key point is including the real error message in the unit test result to have a quick hint of why the test is failing.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment12</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment12</guid><pubDate>Thu, 05 Apr 2012 17:26:03 GMT</pubDate></item><item><title>Matthew Wills commented on Got to debug is a bug, fix your error messages</title><description>Whoops, IsNull(message) should be IsNull(message, message).</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment11</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment11</guid><pubDate>Thu, 05 Apr 2012 08:30:21 GMT</pubDate></item><item><title>Matthew Wills commented on Got to debug is a bug, fix your error messages</title><description>I'd likely lean towards:

var message = backupStatus.Messages.Where(x =&gt; x.Severity == BackupStatus.BackupMessageSeverity.Error).Select(z =&gt; z.Message).FirstOrDefault();

Assert.IsNull(message);

to avoid the if.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment10</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment10</guid><pubDate>Thu, 05 Apr 2012 08:25:51 GMT</pubDate></item><item><title>Karep commented on Got to debug is a bug, fix your error messages</title><description>And also why you once break out of while (and method) and in other place you return?</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment9</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment9</guid><pubDate>Wed, 04 Apr 2012 21:04:18 GMT</pubDate></item><item><title>Karep commented on Got to debug is a bug, fix your error messages</title><description>I hate Assert.False(true.... I was wondering if that was some typo.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment8</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment8</guid><pubDate>Wed, 04 Apr 2012 16:43:50 GMT</pubDate></item><item><title>João P. Bragança commented on Got to debug is a bug, fix your error messages</title><description>He needs to show the actual error message in the tests.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment7</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment7</guid><pubDate>Wed, 04 Apr 2012 16:10:51 GMT</pubDate></item><item><title>Josh Kodroff commented on Got to debug is a bug, fix your error messages</title><description>Umm... what's wrong with:

Assert.That(() =&gt; backup.Messages.Any(x =&gt; x.Severity == BackupStatus.BackupMessageSeverity.Error), Is.True, "Expected to find a backup message error, but didn't find one.");

Pretty explicit in my mind.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment6</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment6</guid><pubDate>Wed, 04 Apr 2012 14:12:52 GMT</pubDate></item><item><title>Ryan commented on Got to debug is a bug, fix your error messages</title><description>Assert.False(true,..) is a really confusing way to write an assertion.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment5</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment5</guid><pubDate>Wed, 04 Apr 2012 12:41:43 GMT</pubDate></item><item><title>Pop Catalin commented on Got to debug is a bug, fix your error messages</title><description>Correction for above: Assert.IsNull should be used</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment4</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment4</guid><pubDate>Wed, 04 Apr 2012 12:07:49 GMT</pubDate></item><item><title>Pop Catalin commented on Got to debug is a bug, fix your error messages</title><description>This is a bit of funny code:
if (message != null)
   Assert.False(true, message.Message);

expecially the 'Assert.False(true...' part.

Can easily be replaced with:

Assert.Fail(message.Message)
or
Assert.IsNotNull(message, message.Message)</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment3</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment3</guid><pubDate>Wed, 04 Apr 2012 12:05:11 GMT</pubDate></item><item><title>Stefan commented on Got to debug is a bug, fix your error messages</title><description>What about all other messages with severity error other than the first? They still get dropped.

Why not use Assert.Fail(message.Message); ?
I find Assert.False(true,...) confusing.</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment2</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment2</guid><pubDate>Wed, 04 Apr 2012 10:29:51 GMT</pubDate></item><item><title>Scooletz commented on Got to debug is a bug, fix your error messages</title><description>Any with predicate will return true if the backupStatus.Messages is empty, so the Assert.False will throw. One of the solutions is what you provided, the second doing .Any() &amp;&amp; .Any(yourPredicate)</description><link>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment1</link><guid>http://ayende.com/153121/got-to-debug-is-a-bug-fix-your-error-messages#comment1</guid><pubDate>Wed, 04 Apr 2012 10:25:14 GMT</pubDate></item></channel></rss>