Problems running .NET 4.0 tests using NUnit 2.5 with (or without) Continuous Testing?

NUnit 2.5 up to and including 2.5.4 fails to properly detect certain revisions of .NET 4.0, causing it to crash. The issue is documented in this bug report on LaunchPad. The bug has been fixed in 2.5.5 and later, so go grab the latest version of NUnit 2.5 and run your tests smoothly again, preferably on each build using Continuous Testing, of course. :)

Posted in C#, Continuous Testing, TDD | Tagged , , , , | Leave a comment

Mocking HtmlHelper in ASP.NET MVC 2 and 3 using Moq

Still having trouble mocking HtmlHelper? This is an update to my previous post on mocking HtmlHelper way back when ASP.NET MVC RC1 was released. Eric notified me through a comment on the post and a question on StackOverflow that the code for ASP.NET MVC RC1 did not work with ASP.NET MVC 2. The code in this post should work with ASP.NET MVC 2 and ASP.NET MVC 3 Preview 1.


public static HtmlHelper CreateHtmlHelper(ViewDataDictionary vd)
{
    Mock<ViewContext> mockViewContext = new Mock<ViewContext>(
        new ControllerContext(
            new Mock<HttpContextBase>().Object,
            new RouteData(),
            new Mock<ControllerBase>().Object),
        new Mock<IView>().Object,
        vd,
        new TempDataDictionary(),
        new Mock<TextWriter>().Object);
    var mockViewDataContainer = new Mock<IViewDataContainer>();
    mockViewDataContainer.Setup(v => v.ViewData)
        .Returns(vd);
    return new HtmlHelper(mockViewContext.Object,
                            mockViewDataContainer.Object);
}

Posted in C#, Code, Technical | Tagged , , , , , , , | Leave a comment

Continuous Testing for Visual Studio

The other night is was playing around with a side project. I try to use a rather strict TDD approach for these projects, and so I run my tests a lot of times as I move forward, and spend quite some time waiting for the result before I move forward. This is a tedious and frankly unnecessary manual step; what I needed was continuous testing – unit tests that test themselves continuously, making sure I don’t break anything.

I remembered reading about JUnit Max by Kent Beck, a continuous testing plugin for Eclipse, that runs your unit tests in the background and unobtrusively tells you when a test fails, allowing you to do what you do best: write code. JUnit Max seems like a great thing, and now I needed the same thing for Visual Studio. A quick Google didn’t yield any add-ins, extensions or packages, so I decided to create one.

The result is Continuous Testing for Visual Studio, a small extension which runs your unit tests each time you build your solution, and reports failing tests to the error list so you can navigate to the line that failed and make the test pass. The extension significantly improves my workflow by removing a tedious manual step of running unit tests, so I encourage you to take it for a spin. Continuous Testing can be downloaded for Visual Studio 2008 and Visual Studio 2010. Future updates and versions will be announced on the Continuous Testing home page.

UPDATE Jun 17th, 2010: I’ve receive a lot of feedback through various solutions online. To be able to help you and/or improve Continuous Testing for Visual Studio, I need samples from you that reproduce the problems you are experiencing. Do not hesitate to leave a comment here, and provide your e-mail address when commenting, and you will receive a reply.

Posted in Announcements, Code, Continuous Testing, TDD | 13 Comments

A Software Craftsmans Bookshelf

A (long) while ago, Gøran Hansen tagged me and invited me to share a set of recommended books. Reorganizing my book shelves, the tag came back to mind, and I decided to name a few of the books that I have learned from. The first three are essential, the rest are great books you should read.

Posted in Uncategorized | 2 Comments

Copyable available on GitHub

People actually download and use Copyable, and they tend to use it in scenarios I haven’t used it in. This results in bug reports and patch submissions. So far, these have been given to me by e-mail or by blog comment, neither of which is a particularly great way of receiving them. So after receiving another one today, I finally got around to putting Copyable on GitHub.

The version I put up includes several enhancements from the latest release:

  • It uses FormatterServices.GetUninitializedObject and hence does not depend on a parameterless constructor or custom instance provider (but you can of course still create an instance provider if you want to control object initialization)
  • The bug with copy semantics for already visited objects submitted by Walter Oesch has been fixed
  • The bug with inherited fields found by Alex, and the patch submitted for it, has been incorporated

Bleeding edge Copyable can be found at http://github.com/havard/copyable. The clone URL is git://github.com/havard/copyable.git. Now go fix your own bugs! Or even better, enhance the framework.

Posted in Announcements, C#, Code, Technical | Tagged , , , , , , , , | 2 Comments