Skip to main content

Run your unit tests on the web

How do you show a client what unit tests are, and what they are good for? Sure, you can lecture them in all the time and money they will save by not hunting for bugs, but it will still be an abstract thing for them. They will never get in touch with the unit tests. I was thinking about this while going home through Uppsala on my bike. What if there was a UnitTestDataSource that could run all your unit tests. Then it would be easy to just hook up a Repeater and display the results in any way you want to. I coded most of the DataSourceControl there on the bike, in my head and just typed it down when I came home. This is the result: UnitTestDataSource.cs

This includes the following:

  • NUnit test runner
  • Support for ExpectedExceptionAttribute
  • Support for IgnoreAttribute

Not included in this release

  • TestFixtureSetup/TestFixtureTeardown
  • TestSetup/TestTearDown
  • Category

Usage: You will probably need to add this to your web.config.

<system.web>
    <pages>
      <controls>
        <add tagPrefix="litemedia" namespace="LiteMedia.Utils.Web" assembly="LiteMedia.Utils" />
      </controls>
    </pages> 
</system.web>

And this is an example of how it could be used in ASP.NET markup.

<litemedia:UnitTestDataSource runat="server" ID="UnitTestDataSource" AssemblyName="LiteMedia.Mint.UnitTests" OnLoad="DataBind" />
<asp:Repeater runat="server" DataSourceID="UnitTestDataSource" OnLoad="DataBind">
    <HeaderTemplate><ul></HeaderTemplate>
    <ItemTemplate>
        <li class="<%# GetSuccessClass(Container.DataItem) %>">
            <span class="name"><%# Container.DataItem %></span>
            <p class="exception <%# GetSuccessClass(Container.DataItem) %>">
                <%# GetException(Container.DataItem) %>
            </p>
        </li>
    </ItemTemplate>
    <FooterTemplate></ul></FooterTemplate>
</asp:Repeater>

comments powered by Disqus