<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>CTRLALT313373.com - Unit Testing</title>
    <link>http://weblog.ctrlalt313373.com/</link>
    <description>.Net Wanderings</description>
    <language>en-us</language>
    <copyright>David A. Osborn</copyright>
    <lastBuildDate>Mon, 17 Mar 2008 00:39:55 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>davido@ctrlalt313373.com</managingEditor>
    <webMaster>davido@ctrlalt313373.com</webMaster>
    <item>
      <trackback:ping>http://weblog.ctrlalt313373.com/Trackback.aspx?guid=b7804d2e-f1ef-4b30-a210-33ddda9da810</trackback:ping>
      <pingback:server>http://weblog.ctrlalt313373.com/pingback.aspx</pingback:server>
      <pingback:target>http://weblog.ctrlalt313373.com/PermaLink,guid,b7804d2e-f1ef-4b30-a210-33ddda9da810.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://weblog.ctrlalt313373.com/CommentView,guid,b7804d2e-f1ef-4b30-a210-33ddda9da810.aspx</wfw:comment>
      <wfw:commentRss>http://weblog.ctrlalt313373.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b7804d2e-f1ef-4b30-a210-33ddda9da810</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Well its official <a href="http://blogs.giffordconsulting.com">The Gifford</a> has
turned me into a code coverage addict. After he helped me through writing my first
unit test using <a href="http://www.nunit.org/index.php">NUnit</a> the concept slowly
started sinking in and I'm now addicted to code coverage. Writing NUnit tests is so
easy that I don't understand why everyone won't do it, which is causing me to get
a bit frustrated with people as it gives me the impression that they just don't care.
I can't remember the number of times that I have gotten rather pissed because someone
has changed my code and broken functionality and in some cases I've even broken my
own code when I've had to go in and make changes after not looking at it for some
time. Unit testing can <strong>minimize</strong> these hair pulling moments by giving
you more confidence that what was supposed to be happening before you touched the
code still happens after you touched it. If someone is in muddling around in your
code and breaks something, you'll know immediately when they check in and the test
doesn't pass on the build server. It all comes down to code quality and I have begun
to notice recently that code quality everywhere sucks. 
</p>
        <p>
If you're not using unit testing of some sort then I think it just boils down to pure
ignorance. Either you see the value of unit tests, but don't know how to write them
and are too lazy to exert the effort to learn how, or you are just too ignorant to
see the value of them. I fell into the first group. I've always seen how they could
be helpful, but never took the time to learn how to do them. In the last couple weeks
I've been really thinking about code quality with the product that I am building with
a couple partners. We decided to build this product because we had gotten stuck working
with another product that we thought had many problems and was a pain to work with.
I realized that we were starting to walk down the same path, rushing to get a beta
out, sacrificing design and architecture for deadlines. There are plenty of poor applications
on the market and I don't want to be contributing to that. I want to produce a quality
product or nothing at all because in the long run if we produce a poor quality product
then we get stuck supporting that poor quality and our customers are stuck working
with it. While assessing quality I kept coming back to our lack of unit testing and
the fact that things kept breaking that worked fine the day before. This motivated
me to overhaul the build server so that it runs NUnit tests automatically and then
uses <a href="http://www.ncover.com/">NCover</a> to provide statistics on the code
that is covered by unit tests and the code that is not covered. Then to take it one
step further I built a screensaver that runs on the monitor of the build server that
displays the overall percent of code coverage from the project in bright flashing
red while it is under the coverage goal. (Currently <a href="http://www.flofactory.com">FloFactory</a> is
at 9.5% code coverage with a coverage goal of 50%.) I look forward to the day that
that text turns green to indicate that we have met our code coverage goal (and then
I'll raise the goal). 
</p>
        <p>
I'm sure plenty of people would argue about the value of unit testing, pointing out
various short coming with unit testing which I am sure are all valid in certain scenarios,
but if you're following a tiered structure for your application, keep your logic out
of the UI and keep your data access separate, then you should have an entire service
layer that can be unit tested. Does having unit tests mean your code is perfect, of
course not. It's not a silver bullet for quality but it is one tool to provide a bit
more certainty about an application. 
</p>
        <p>
Where I am really struggling is motivating others to improve their code quality, understanding
the importance of testing and getting them to write even one unit test. I realize
that unit testing can't cover your entire application, but it's a start and if you
start thinking about how you structure your application you'll starting seeing better
ways to design things so that you can properly test them using such things as mock
objects and inversion of control containers. <a href="http://blogs.giffordconsulting.com">The
Gifford</a> told me once that he goes by the statement "You don't have write unit
tests, but don't break mine." Whereas I like this statement, I don't think it motives
any one to write a single unit test, so I'm adding onto this by trying to make the
statistics more visible. Hopefully if someone checks in code that lowers the overall
coverage percent, that they can see very clearly on the build server screensaver,
they may feel more motivated to raise that number. 
</p>
        <p>
As for myself, I'm going to keep digging into ways to increase quality so that the
final product is stable and worth using. One last thing to point out is that if you
plan to get started unit testing and are going to use NUnit then I would suggest picking
up a copy of <a href="http://www.jetbrains.com/resharper/">Resharper</a>. It allows
you to run your NUnit tests extremely easily from Visual Studio taking some of the
headaches out of writing them.
</p>
        <img width="0" height="0" src="http://weblog.ctrlalt313373.com/aggbug.ashx?id=b7804d2e-f1ef-4b30-a210-33ddda9da810" />
      </body>
      <title>Code Coverage Addict</title>
      <guid isPermaLink="false">http://weblog.ctrlalt313373.com/PermaLink,guid,b7804d2e-f1ef-4b30-a210-33ddda9da810.aspx</guid>
      <link>http://weblog.ctrlalt313373.com/2008/03/17/CodeCoverageAddict.aspx</link>
      <pubDate>Mon, 17 Mar 2008 00:39:55 GMT</pubDate>
      <description>&lt;p&gt;
Well its official &lt;a href="http://blogs.giffordconsulting.com"&gt;The Gifford&lt;/a&gt; has
turned me into a code coverage addict. After he helped me through writing my first
unit test using &lt;a href="http://www.nunit.org/index.php"&gt;NUnit&lt;/a&gt; the concept slowly
started sinking in and I'm now addicted to code coverage. Writing NUnit tests is so
easy that I don't understand why everyone won't do it, which is causing me to get
a bit frustrated with people as it gives me the impression that they just don't care.
I can't remember the number of times that I have gotten rather pissed because someone
has changed my code and broken functionality and in some cases I've even broken my
own code when I've had to go in and make changes after not looking at it for some
time. Unit testing can &lt;strong&gt;minimize&lt;/strong&gt; these hair pulling moments by giving
you more confidence that what was supposed to be happening before you touched the
code still happens after you touched it. If someone is in muddling around in your
code and breaks something, you'll know immediately when they check in and the test
doesn't pass on the build server. It all comes down to code quality and I have begun
to notice recently that code quality everywhere sucks. 
&lt;/p&gt;
&lt;p&gt;
If you're not using unit testing of some sort then I think it just boils down to pure
ignorance. Either you see the value of unit tests, but don't know how to write them
and are too lazy to exert the effort to learn how, or you are just too ignorant to
see the value of them. I fell into the first group. I've always seen how they could
be helpful, but never took the time to learn how to do them. In the last couple weeks
I've been really thinking about code quality with the product that I am building with
a couple partners. We decided to build this product because we had gotten stuck working
with another product that we thought had many problems and was a pain to work with.
I realized that we were starting to walk down the same path, rushing to get a beta
out, sacrificing design and architecture for deadlines. There are plenty of poor applications
on the market and I don't want to be contributing to that. I want to produce a quality
product or nothing at all because in the long run if we produce a poor quality product
then we get stuck supporting that poor quality and our customers are stuck working
with it. While assessing quality I kept coming back to our lack of unit testing and
the fact that things kept breaking that worked fine the day before. This motivated
me to overhaul the build server so that it runs NUnit tests automatically and then
uses &lt;a href="http://www.ncover.com/"&gt;NCover&lt;/a&gt; to provide statistics on the code
that is covered by unit tests and the code that is not covered. Then to take it one
step further I built a screensaver that runs on the monitor of the build server that
displays the overall percent of code coverage from the project in bright flashing
red while it is under the coverage goal. (Currently &lt;a href="http://www.flofactory.com"&gt;FloFactory&lt;/a&gt; is
at 9.5% code coverage with a coverage goal of 50%.) I look forward to the day that
that text turns green to indicate that we have met our code coverage goal (and then
I'll raise the goal). 
&lt;/p&gt;
&lt;p&gt;
I'm sure plenty of people would argue about the value of unit testing, pointing out
various short coming with unit testing which I am sure are all valid in certain scenarios,
but if you're following a tiered structure for your application, keep your logic out
of the UI and keep your data access separate, then you should have an entire service
layer that can be unit tested. Does having unit tests mean your code is perfect, of
course not. It's not a silver bullet for quality but it is one tool to provide a bit
more certainty about an application. 
&lt;/p&gt;
&lt;p&gt;
Where I am really struggling is motivating others to improve their code quality, understanding
the importance of testing and getting them to write even one unit test. I realize
that unit testing can't cover your entire application, but it's a start and if you
start thinking about how you structure your application you'll starting seeing better
ways to design things so that you can properly test them using such things as mock
objects and inversion of control containers. &lt;a href="http://blogs.giffordconsulting.com"&gt;The
Gifford&lt;/a&gt; told me once that he goes by the statement "You don't have write unit
tests, but don't break mine." Whereas I like this statement, I don't think it motives
any one to write a single unit test, so I'm adding onto this by trying to make the
statistics more visible. Hopefully if someone checks in code that lowers the overall
coverage percent, that they can see very clearly on the build server screensaver,
they may feel more motivated to raise that number. 
&lt;/p&gt;
&lt;p&gt;
As for myself, I'm going to keep digging into ways to increase quality so that the
final product is stable and worth using. One last thing to point out is that if you
plan to get started unit testing and are going to use NUnit then I would suggest picking
up a copy of &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper&lt;/a&gt;. It allows
you to run your NUnit tests extremely easily from Visual Studio taking some of the
headaches out of writing them.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://weblog.ctrlalt313373.com/aggbug.ashx?id=b7804d2e-f1ef-4b30-a210-33ddda9da810" /&gt;</description>
      <comments>http://weblog.ctrlalt313373.com/CommentView,guid,b7804d2e-f1ef-4b30-a210-33ddda9da810.aspx</comments>
      <category>Development</category>
      <category>NUnit</category>
      <category>Testing</category>
      <category>Unit Testing</category>
    </item>
  </channel>
</rss>