<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-AU" xmlns:media="http://search.yahoo.com/mrss/">
  <id>https://david.gardiner.net.au/tags/Testing.xml</id>
  <title type="html">David Gardiner - Testing</title>
  <updated>2026-04-15T00:26:28.866Z</updated>
  <subtitle>Blog posts tagged with &apos;Testing&apos; - A blog of software development, .NET and other interesting things</subtitle>
  <rights>Copyright 2026 David Gardiner</rights>
  <icon>https://www.gravatar.com/avatar/37edf2567185071646d62ba28b868fab?s=64</icon>
  <logo>https://www.gravatar.com/avatar/37edf2567185071646d62ba28b868fab?s=256</logo>
  <generator uri="https://github.com/flcdrg/astrojs-atom" version="3">astrojs-atom</generator>
  <author>
    <name>David Gardiner</name>
  </author>
  <link href="https://david.gardiner.net.au/tags/Testing.xml" rel="self" type="application/atom+xml"/>
  <link href="https://david.gardiner.net.au/tags/Testing" rel="alternate" type="text/html" hreflang="en-AU"/>
  <category term="Testing"/>
  <category term="Software Development"/>
  <entry>
    <id>https://david.gardiner.net.au/2026/04/exceptional-unit-tests</id>
    <updated>2026-04-01T09:30:00.000+10:30</updated>
    <title>Exceptional unit tests</title>
    <link href="https://david.gardiner.net.au/2026/04/exceptional-unit-tests" rel="alternate" type="text/html" title="Exceptional unit tests"/>
    <category term=".NET"/>
    <category term="Testing"/>
    <published>2026-04-01T09:30:00.000+10:30</published>
    <summary type="html">Unexpected exceptions being thrown and caught inside application
code, that weren&apos;t obvious until the unit test was run under a debugger.</summary>
    <content type="html">&lt;p&gt;I was working on a .NET application that had a nice suite of unit tests, and pleasingly the tests were all passing.&lt;/p&gt;
&lt;p&gt;While making a change to the code, one of the tests failed (which is the whole point of having tests!). To better understand the reason for the failure I re-ran the test in the Visual Studio debugger.&lt;/p&gt;
&lt;p&gt;I noticed something strange - the system under test was throwing a &lt;code&gt;NullReferenceException&lt;/code&gt;, which was then being caught (and effectively swallowed) by an outer &lt;code&gt;try&lt;/code&gt;/&lt;code&gt;catch&lt;/code&gt; block.&lt;/p&gt;
&lt;p&gt;The surprising thing was that this test should not have been doing that - a pretty straightforward test of some business logic. It was just a coincidence that in this case the exception wasn&apos;t changing the observable behaviour of the code, which is why the test had previously been passing.&lt;/p&gt;
&lt;p&gt;In this case, the underlying cause of the &lt;code&gt;NullReferenceException&lt;/code&gt; turned out to be a missing mocked method on a dependency.&lt;/p&gt;
&lt;p&gt;It did make me wonder though, are there other similar issues hidden elsewhere in the unit tests?&lt;/p&gt;
&lt;p&gt;To find out, I opened up Visual Studio&apos;s &lt;a href=&quot;https://learn.microsoft.com/visualstudio/debugger/managing-exceptions-with-the-debugger?view=visualstudio&amp;amp;WT.mc_id=DOP-MVP-5001655&quot;&gt;Exception Settings window&lt;/a&gt; (&lt;strong&gt;Debug&lt;/strong&gt; | &lt;strong&gt;Windows&lt;/strong&gt; | &lt;strong&gt;Exception Settings&lt;/strong&gt;), searched for &apos;NullReferenceException&apos; and ensured that it was set to &apos;Break when thrown&apos;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://david.gardiner.net.au/_astro/exception-settings.BskstRPv_Z1zU8Gz.webp&quot; alt=&quot;Screenshot of Exception Settings window in Visual Studio&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I then ran the entire test suite under the debugger (&lt;strong&gt;Test&lt;/strong&gt; | &lt;strong&gt;Debug All Tests&lt;/strong&gt;) and took note of each time the debugger stopped with a thrown exception. Some of these were other exception types that were expected (and I could turn off the &apos;Break when thrown&apos; on those if they were too noisy).&lt;/p&gt;
&lt;p&gt;I ended up finding a few other tests that had similar issues. There were also some paths in the application code where null handling could be made more robust.&lt;/p&gt;
&lt;p&gt;The tests still pass, but they should now be a bit more reliable in the future for the next developer who is relying on them when making application code changes (which could be me!)&lt;/p&gt;
</content>
    <media:thumbnail url="https://david.gardiner.net.au/_astro/exception-settings.BskstRPv.png" width="942" height="498"/>
    <media:content medium="image" url="https://david.gardiner.net.au/_astro/exception-settings.BskstRPv.png" width="942" height="498"/>
  </entry>
  <entry>
    <id>https://david.gardiner.net.au/2006/02/unit-testing-events-with-anonymous</id>
    <updated>2006-02-22T17:18:00.000+10:30</updated>
    <title>Unit Testing Events with Anonymous Delegates in .NET 2.0</title>
    <link href="https://david.gardiner.net.au/2006/02/unit-testing-events-with-anonymous" rel="alternate" type="text/html" title="Unit Testing Events with Anonymous Delegates in .NET 2.0"/>
    <category term="Testing"/>
    <category term="UniSA"/>
    <published>2006-02-22T17:18:00.000+10:30</published>
    <summary type="html">How do you unit test your event code? You use Anonymous Delegates Here&apos;s a sample unit test that I&apos;ve created that makes use of this technique:</summary>
    <content type="html">&lt;p&gt;How do you unit test your event code? You use &lt;a href=&quot;https://web.archive.org/web/20080323060742/http://www.peterprovost.org:80/archive/2005/05/29/3497.aspx&quot;&gt;Anonymous Delegates&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here&apos;s a sample unit test that I&apos;ve created that makes use of this technique:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;        [TestMethod()]
        public void UpdateTestTimesTest()
        {
            object expected = UniSA.UniSAnet.SmartMark.DataAccess.DataItemChangedEventArgs.ChangeType.Update;
            object actual = null;
            UniSA.UniSAnet.SmartMark.DataAccess.TestComponent.DataItemChanged += delegate(object sender, UniSA.UniSAnet.SmartMark.DataAccess.DataItemChangedEventArgs e)
            {
                actual = e.Change;
            };

            Test test = UniSA.UniSAnet.SmartMark.DataAccess.TestComponent.GetTest(UnitTestingTestId);
            test.MinutesAllowed += 1;
            UniSA.UniSAnet.SmartMark.DataAccess.TestComponent.UpdateTestTimes(test);
            Assert.AreEqual(expected, actual);
        }
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <id>https://david.gardiner.net.au/2005/07/sourceforgenet-project-info-jsunit</id>
    <updated>2005-07-15T14:30:00.000+09:30</updated>
    <title>SourceForge.net: Project Info - JsUnit</title>
    <link href="https://david.gardiner.net.au/2005/07/sourceforgenet-project-info-jsunit" rel="alternate" type="text/html" title="SourceForge.net: Project Info - JsUnit"/>
    <category term=".NET"/>
    <category term="JavaScript"/>
    <category term="Testing"/>
    <category term="Unit Testing"/>
    <published>2005-07-15T14:30:00.000+09:30</published>
    <summary type="html">SourceForge.net: Project Info - JsUnit: &quot;JsUnit is a unit testing framework for client-side JavaScript in the tradition of the XUnit frameworks.&quot; I&apos;ve also been dabbling with NUnitAsp for unit testing of some ASP.NET pages, but the current version only does server-side testing (eg. no client Javascript stuff).</summary>
    <content type="html">&lt;p&gt;&lt;a href=&quot;http://sourceforge.net/projects/jsunit/&quot;&gt;SourceForge.net: Project Info - JsUnit&lt;/a&gt;: &quot;JsUnit is a unit testing framework for client-side JavaScript in the tradition of the XUnit frameworks.&quot; I&apos;ve also been dabbling with &lt;a href=&quot;https://web.archive.org/web/20251221200939/https://nunitasp.sourceforge.net/&quot;&gt;NUnitAsp&lt;/a&gt; for unit testing of some ASP.NET pages, but the current version only does server-side testing (eg. no client Javascript stuff).&lt;/p&gt;
</content>
  </entry>
</feed>
