This is the second and last part of my blog post titled 10 Tips to Optimize Your Time. If you haven’t read part 1, go ahead!

Only plan one visit every weekend if possible

We have a large family.  Both my wife and I are children of divorced parents and therefore have four sets of parents/grandparents.  The thing is, those grandparents want to see their grandson (and us) ALL the time.  Keeping grandparents in restraints has been a major issue for us.  We try to see family on the weekends and always only plan one of the days.  This gives us the other day to concentrate on our son and when he’s tucked in, coding time starts!

Pay someone to do tedious work

This is something that I’m not good at, but I keep trying to find new ways of outsourcing all of those tedious tasks.  Why not pay someone to clean your house?  Don’t wash the car yourself.  The car wash is a great alternative and you can catch up on your e-mail or Twitter while the old, dusty car gets a makeover.  Admittedly, we (maybe it’s I) drink a lot of soda.  Nothing sucks more than putting all of those empty cans in the can recycler.  I’m planning to make a deal with one of the kids on the street, that he will get the bottle deposit if he comes by and empties my shed for empty bottles and cans once in a while.  The point here is that people in the IT business make enough money to pay someone to do all of those tasks that you don’t like.  Just do it!

Buy work you can’t do yourself

It’s amazing what people do for money nowadays.  Before having my son, I would gladly sit down and scan hundreds of old photos, which takes a long time.  These days, I just send them for scanning in Morocco.  Yes this isn’t free, but doing manual work like that is time consuming and boring.  Last year, I started experimenting with buying help on fiverr.com.  The first couple of months weren’t a great success, but after spending a few more fiverrs, I ended up knowing some pretty talented people, willing to do stuff for $5.  I use fiverr for proof reading, graphics, copy-paste work and other tasks, which I can’t do myself or that I don’t bother to learn.

Don’t do stuff which never leaves your machine

Doing websites or code in general, which only lives on your machine, is fun if you want to learn something.  Doing stuff that other people see either through a website or GitHub is more fun.  I never write code that doesn’t end up on the internet somehow.  I have a principle that everything I do should be monetizable somehow.  I always have ads on my blogs and try monetizing everything from .NET assemblies to Chrome plugins.  I don’t even earn 1 % of my day-job paycheck each month, but the feeling of earning enough to cover your expenses on fiverr and hosting is enough to drive me. The point here is, that doing personal stuff quickly becomes a time consumer, cause you don’t get any feedback and you could have used your time on something else.

Buy gifts for your wife/girlfriend

If your better half doesn’t work in IT, he/she probably doesn’t understand that your job can also be your hobby.  My wife has become very understanding over the years.  A technique you can use, if you aren’t as lucky as me, is to buy time consuming gifts for the other part.  The Sex and the City boxset is a great example of how to make your wife happy for several hours.  Do not, and I must stress, DO NOT give her the impression that you want to see the damn thing with her though :) Make sure to spend time with your other half, but make an arrangement for one or two nights a week, where you can get into the zone without being interrupted.

Happy coding!

Share this post:

Share to Google Plus

A couple of people have asked me how I find time to do all of my hobby projects while having a house, a wife, a son, family and friends all at the same time.  The answers I gave inspired me to write this blog post.  While I’m extremely bad at focusing on a single coding projects, I’ve done a lot to optimize the time I actually have for all my experimental coding.  This the the following blog post is an attempt to explain some of the things I do to find some extra hours.

Minimize the time you talk on the phone

Face it!  Nobody needs to talk to their mom every day.  My wife thinks she does, but when I overhear their conversations, it’s always superficial small talk.  I talk to my parents once a week on a fixed time.  Agreeing on the time of the call makes it possible to plan your night and not feel frustrated when your mom calls you while you’re “in the zone” to tell you about her yoga progress.  Also, turning on the phone’s silent option keeps you from talking to sales people and other annoying disturbances.  If you’re the type of person who needs to talk to your friends all the time, meet up with them once in a while instead of calling them each night.  I chat a lot with my more neardy friends, which works great because I can code on my other screen in my dual screen setup while chatting on the other.

No weekly scheduled events

I never accept weekly scheduled events.  When someone asks me if I want to play badminton with them every Tuesday and Thursday night, I simply say no.  Playing once in a while is fun and you should definitely do it.  However, promising your time two nights a week is a major timer spender. The point here is only do it if you’re really into it!

Don’t watch live TV

A couple of years ago I watched a lot of live TV.  A LOT!  My wife and I watched everything from the news to programs titled, “100 Greatest Hollywood Screw-Ups”.  After we had our son, we canceled the cable TV and now only have something like 2 watchable channels.  This is probably the best decision we’ve made in years.  We still watch movies and shows, but always on DVD or web content.  This means that we can sit down and watch five episodes of a show in one night without being bothered by commercials and other time consuming stuff.

Optimize your shopping

When we lived in an apartment in the city 4 years ago, we discussed what we would have for dinner every day and went to the food store to buy it.  Doing weekly meal planning, gave us something like an hour extra everyday but on Monday when we do all of our shopping for the week.  Shopping for the week doesn’t take much longer than shopping for 1 or 2 days.  Also, I buy must of my stuff online from hardware to clothes.

Do stuff with your kids

I’ve heard a lot of people with kids complaining about too few hours to code.  These people typically wait to do stuff like cleaning and shopping until the kids are asleep and for that reason, they don’t starts coding until 10 in the evening.  While we love to spend time with our son, we also treasure the time when he is tucked in.  People are too afraid to admit this, but we all need time for ourselves.  We do a lot of stuff at home with our son and he also joins one of use shopping each week.  He loves it!

In the next post I reveal the final 5 tips to optimize your time.

Share this post:

Share to Google Plus

I don’t think I ever got to announcing NuGetFeed.org. NuGet Feed is a great extension to NuGet, which most .NET developers should know by now.  With NuGetFeed.org you will be able to follow your favorite NuGet package releases with a RSS reader of your choice.  Also, you will find a couple of plugins at the main NuGetFeed.org site.  One is for Google Chrome, which decorates the NuGet.org site with RSS links (it should really have been there from the beginning).  Another plugin is for Visual Studio, which lets you export all of your referenced NuGet packages to NuGetFeed.org.

I wanted to tell you the story behind NuGetFeed.org, because it has been an interesting experience for me.  About four months ago, I spoke with two of my co-workers, Jesper and Christian, about the lack of possibilities of getting notified, when someone releases a new version of their NuGet package.  You have to manually open the NuGet Package Manager and search for updates, which I don’t do that often.  I must have done a good job convincing them, because we quickly agreed to do something about the problem.  We could have joined the NuGet team, made pull requests or similar, but we decided to try another approach.

While Jesper started working on the graphics for the NuGetFeed.org website, Christian looked into doing the actual RSS feeds through the NuGet API.  I decided to use my existing knowledge about developing extensions for Google Chrome to make a kick-ass chrome plugin with links to NuGetFeed.org (pretty much a greasemonkey script) that would enhance visitors’ experience at the NuGet.org site.  Also, one of the initial ideas was to develop an add-in for Visual Studio, making it possible to export all of a project’s references to NuGetFeed.org.

We chose ASP.NET MVC for developing the website and Twitter Bootstrap for most of the UI.  Both frameworks totally kicks ass and allowed us to develop something that looks pretty nice, in only a short period of time.  For hosting, we decided to go with AppHarbor, the Danish start-up which makes Azure look like mainframe-programming.  AppHarbor supports Git, which is our preferred VCS at the moment.  Also, a single instance at AppHarbor is provided free of charge, as well as free MongoDB hosting at MongoHQ.

After a week or so, the main service and plugins started to take shape.  Remember, this was done in out spare time.  I ended up using too much time on the Visual Studio add-in and, honestly, I was very disappointed with how difficult it was.  There’s a new and shiny Visual Studio SDK using MEF, but I couldn’t find documentation on the extension points we needed for our add-in.  Therefore, I ended up developing a VSPackage, which is the old way of doing things.  The whole thing felt a lot like coding COM, which I’d forgot all about years ago.  I think the reason for the lack of great add-ins for Visual Studio is caused by old API’s which are difficult to develop against.  I really hope that Microsoft will improve the SDK over time, letting me port my nasty VSPackage to something sweeter.

Anyway, a week or so after the first night of coding, the first version of both the main site and the Chrome plugin were finished. We went live and got a few visits per day.  A couple of days after, the Visual Studio add-in went live on the Visual Studio Gallery and visits suddenly went through the roof.  I was amazed to see the impact in Analytics the day after the Visual Studio add-in release. People must be using the gallery after all.  Also, all new add-ins were published to the MSDN News Twitter account, which have almost 6,000 followers now.

A few days later, we were lucky enough to get mentioned on Chris Alcock’s blog The Morning Brew (TMB).  For those of you who don’t know TMB, it’s a great developer blog with a daily post summarizing yesterday’s most important news.  Again, we reached an all time record on the visit count on NuGetFeed.org.

NuGetFeed.org has been running for almost 6 months now and I’m happy to see that someone is using our service every day.

Share this post:

Share to Google Plus

Let’s face it, it doesn’t make sense to keep and maintain unit tests not executed on a continuous basis. In my previous post, I looked at a unit test framework for JavaScript called QUnit. While commonly used unit test runners like NUnit, JUnit and MSTest have great support on TeamCity, there is no build-in support for executing QUnit tests (yet). During my recent adventures with QUnit, I wanted to be able to execute my new and shiny QUnit-tests on TeamCity. It turned out that it was almost as easy as integrating the supported framework.

Red Badger implemented a nice NuGet package called QUnitTeamCityDriver. The package consists of two JavaScript-files: QUnitTeamCityDriver.js and QUnitTeamCityDriver.phantom.js. The first file contains logic to output results from running the QUnit tests to a format understandable by TeamCity. This file should be referenced just after the reference to QUnit.js in your tests. The second file is used on TeamCity to integrate with PhantomJS. PhantomJS is a windowless browser with a nice JavaScript API to control it all.

Before we dig into the configuration on TeamCity, we need to specify a HTML-container referencing all the js-files containing unit-tests. This is probably the biggest flaw right now because ReSharper does a nice job avoiding this container. What you need is a HTML-file looking that looks like this:

<!DOCTYPE html>
<html>
 <head>
 <title>JavaScript Tests</title>
 <link rel="stylesheet" href="qunit.css" />
 <script type="text/javascript" src="jquery-1.7.1.js"></script>
 <script type="text/javascript" src="qunit.js"></script>
 <script type="text/javascript" src="QUnitTeamCityDriver.js"></script>
</head>
 <body>
 <h1 id="qunit-header">QUnit example</h1>
 <h2 id="qunit-banner"></h2>
 <div id="qunit-testrunner-toolbar"></div>
 <h2 id="qunit-userAgent"></h2>
 <ol id="qunit-tests"></ol>
 <div id="qunit-fixture">test markup, will be hidden</div>
 <script type="text/javascript" src="tests.js"></script>
</body>
</html>

The file contains some basic HTML elements and references to jQuery, QUnit and QUnitTeamCityDriver. At the bottom, I reference the tests.js-file which I implemented in my previous blog post. So what’s the main problem with this file? Each time a new js-file containing test are added to our project, we need to manually add a reference to this file at the bottom. I haven’t found a nicer solution to this problem, so until a better approach emerges, I’ll continue using this file.

In order to get the tests running on TeamCity, you need to download and extract PhantomJS on TeamCity. Unfortunately, PhantomJS doesn’t come as a NuGet package, which is why you need to do this manually. Place PhantomJS in a folder like c:\phantomjs. Add a new build step just after you run your unit tests called, “Run JS tests”, or another name of your choice. Your settings should look like this:

In the text area to the right of “Command parameters”, I reference two files. The first file is the QUnitTeamCityDriver.phantom.js-file which came with the QUnitTeamCityDriver NuGet-package. The second is a reference to the html-file created previously in this blog post. Save the build-step and Run the build. If everything looks green, you will be able to see the QUnit-tests alongside your NUnit-tests in the “Test” tab under each build. Simple and nicely integrated!

Share this post:

Share to Google Plus

One of the areas that I never really dug into is unit testing JavaScript code. I have a background as a backend developer and for me, NUnit has been sufficient for years. During the last couple of years, I started implementing a few websites and also switched my working place from Trifork to eBay so I could expand my web knowledge. The switch opened up an entire new world for me, the world of JavaScript. I had previously written some JavaScript before starting at eBay, but I never really had the time to sit down and fully understand the language. Therefore, I never really used the full potential of JavaScript, but I still wrote a lot of the application on the server (in c#). That’s why I decided to look at unit-testing JavaScript.

Some developers argue that JavaScript shouldn’t be unit-tested because it is part of the UI. These people typically use something like Selenium to test the client, but in my experience, Selenium tests are like integration-tests: hard to write and maintain. C’mon guys, this is one of the reasons why we write unit-tests of the server, to be able to test single units and ease the debugging process when bugs are introduced. Unit-testing the UI becomes essential in today’s thick HTML5 applications.

For my JavaScript unit test experiment, I needed a framework and while there are a lot to choose from, I wanted to try out QUnit. QUnit is from the guys who brought you jQuery and is actually used to test jQuery itself. I simply can’t say it enough, but I LOVE jQuery. For this one reason I decided to try and see if I would love QUnit as well.

QUnit turned out to be pretty straight forward. Let’s look at a simple test. Save the following JavaScript to a file called tests.js (or a name of your choice):

test("Can Add Two Strings", function () {
  // Arrange
  var str1 = "Hello";
  var str2 = "World";

  // Act
  var result = str1 + " " + str2;

  // Assert
  equal(result, "Hello World");
});

Admittedly, this is probably not the best test, but it illustrates the basic features of QUnit. Every test is specified by calling a test-method from QUnit with a name of the test and a callback containing the actual test. Like NUnit, the asserts are specified by calling methods. equal matches the Assert.AreEqual method in NUnit and there are similar methods like ok for IsTrue and so on. I really like the simple yet strong-type way of writing the test method. No method name prefixes. No attributes. Also, the QUnit guys choose the correct order of the parameters for the equal method. In NUnit, the expected value goes first, which always confused me.

Unit tests exist to be run. So, what do we do to execute the test above? QUnit supplies us with a style sheet and some JavaScript files, which makes the execution pretty straightforward. An even better solution is to use the QUnit-runner in ReSharper (ReSharper 6.x only, sorry Stone Age dudes). In order for ReSharper to know that the tests.js file contains test-methods, you need to add a script reference on the top of the js-file:

/// <reference path="CodeUnderTest.js"/>

The CodeUnderTest.js-filename tells ReSharper that the file contains unit-tests. The file-path is there for information only and should not exist on the file system. In order to get IntelliSense while writing your tests, it’s a good idea to add a reference to the qunit.js-file as well. This reference is not mandatory though, because ReSharper comes bundled with its own version of QUnit. Well now for the good part: Look Ma, my QUnit test is runnable through ReSharper:

Working with QUnit has been like a dream come true. I wouldn’t have guessed that testing JavaScript could be that easy. There’s no excuse not to start implementing unit-tests of JavaScript!

Share this post:

Share to Google Plus

During the last 6 years, I’ve preached unit testing to my colleagues and people attending my test-driven development courses. The set of tools I’ve used for this purpose have been stable, for the most part. This blog post is an attempt to create a snapshot of the tools and frameworks I’m using right now.

Unit-Test Framework and Runner

NUnit has been my preferred tool to execute tests. I did some fooling around with MSTest a couple of years ago, but unlike NUnit, you need to install Visual Studio on the build server to run the tests. The syntax is strange and the test runner for Visual studio sucks. I also looked at xUnit.net which is cool, but the limited support for ReSharper at the time kept me from switching. Let’s admit it: NUnit is the defacto standard these days. The support and community around NUnit is so great, that I will probably not switch anytime soon. I really hope that NUnit looks into the cool things happening in xUnit.net. I also hope that build servers, Visual Studio extensions and other tools integrating unit test frameworks will do a better job of integrating xUnit.net.

Mocking Framework

Rhino Mocks has been my favorite mocking framework for years. I tried Moq two years ago, but quickly switched back to Rhino Mocks due to the strange errors I was receiving from Moq. Last year, I tried Moq again and liked it so much that this is now my favorite mocking framework. I also tried FakeItEasy, but I didn’t really think that it brought anything new to the table.

Buildserver

You might be thinking something like, “Whuuut? Why does the unit-test freak suddenly mention anything about build servers, in the middle of a blog post about unit-testing tools?” Well, without a build server to execute all of your unit-tests, you probably shouldn’t write them in the first place. The build server is a perfect place for conducting regression testing. I typically run all of my unit-tests before committing code, letting the build server run the heavy database-dependent integration-tests. During the last 10 years as a professional software developer, I’ve tried practically all major build servers from homemade bat-scripts over CruiseControl and CruiseControl.NET to TeamCity. TeamCity is my current favorite, with great support for .NET/C#.

Helpers

Also, last year I started using AutoFixture, which is a cool library used to automate the creation of test values. I blogged about AutoFixture a couple of times.

Shouldly is a nice set of extension methods for NUnit if you do not like the Assert.* syntax. I previously blogged about Shouldly as well.

Any opinions on missing frameworks?

Share this post:

Share to Google Plus

I found myself repeatable adding the same Live Template to R# over and over again: The unit-test template. This template adds a method with a method name starting with Can as well as the arrange/act/assert comments, which I’m pretty much in love with. Each time I re-install my old machine or simply get a new one, this is the first template I import. The other day I wanted to share this template with my team-members, but wanted to do something else than just exporting the template and sharing it by mail. It turns out that R# have a great feature to share stuff between team members. I already use this to share R# settings, as well as StyleCop settings (which is available as a R# plugin). The sharing feature also supports live templates, which I was not aware of.

To share your live templates with your team members, navigate to the Templates Explorer in the ReSharper menu inside Visual Studio. On my machine, the This computer layer was selected as shown here:

Select the test-template and export it by clicking the Export-icon. Change the layer to Solution ‘Your SLN’ team-shared and import the file. Close Visual Studio to make sure that the DotSettings file is updated. If not already added, add the file named <your sln>.DotSettings to source control and the live template is shared with your team members, the next time they get that file. Simple and neat, right?

Share this post:

Share to Google Plus

Inspired by my old colleague Mookid, I want to also share what I’ve been working on this year. It has been a crazy and busy year. Even though my wife and I had a son last year, I’ve coded more than ever. Having a baby forces you to focus your time and energy.

Now for the retrospect, ordered by date, describing what I’ve been working on throughout the year.

thomasardal.com
My new year’s resolution last year, was to start blogging. I wrote my very first blog post on the 2nd of January this year under the title, performancedude.com. I blogged a lot during the first few months about performance optimizing web applications, but my passion for blogging expanded to include other subjects like unit testing. Around June, I decided to switch from my performancedude alias, to start blogging on thomasardal.com. In total, I’ve written 27 blog posts this year. I probably won’t blog as much next year, but I will definitely try to write a post once in a while.

MSBuild Shell Extension
January started the year of great. I was lucky to be contacted by a very talented developer, Rami, who wanted to help shine up my 5-year-old power tool for MSBuild, named MSBuild Shell Extension. MSBuild SE is, as the name proposed, a shell extension for running MSBuild scripts from Explorer, Total Commander or similar. I hadn’t really touched the tool for years, which is why I was happy that someone wanted to take over. Before Rami joined the project, the context menu showed from MSBuild SE was 100 % static, but configurable through a config app installed alongside the build runner. When Rami finished, the context menu was generated dynamically with the MSBuild targets from the right-clicked build-file. Rami did 90 % of the worked and I did all I could to help him finish. Great work, Rami! Our work paid off in the end and the tool was downloaded more than 2,000 times. We also got mentioned in Scott Hanselman’s 2011 Ultimate Developer and Power Users Tool List for Windows!

HippoFocus
While still employed by Trifork, I decided to look more into doing extensions for Google Chrome at one of the companies two annual Hackathons. My first real contribution to the community was HippoFocus, a tool to help you set correct focus points when visiting your favorite websites. This is not rocket science. Even though the extension didn’t really reach the masses, I still think that it is one of the most useful extensions I have implemented.

HippoTab
Why I chose the “Hippo”-prefix once more I can’t really tell you, but shortly after releasing HippoFocus, I did HippoTab. HippoTab automatically tabs when you reach the max length of any input field in a html form. Again not rocket science, but it was fun to implement and my JavaScript skills definitely improved.

eBay
Ok, maybe I didn’t invent this one. This story is about my switch from Trifork to eBay in March of 2011. I had worked at Trifork for 3½ years and wanted to try something new where I was able to focus on my .NET web developing skills. Luckily, I was contacted by eBay, who searched for a talented .NET developer (that’s me :) ). I worked at one of eBay’s Danish sites, named bilbasen.dk, for the first couple of months. It was a great learning experience for me, so naturally I was a bit sad when the company decided to split our team in half. My new team was moved to a new project named DealerHub. DealerHub is the nextgeneration application for Danish car-sellers. The project turned out to be an even better learning experience for me because I was given the freedom to design and implement a kick-ass system using multiple buzz-word enabled techs like KnokcoutJS, ASP.NET MVC 3 and RavenDB. Love it!

HippoLink
In the never-ending line of Hippo* Extension for Google Chrome, HippoLink was released. The idea was to convert unclickable URL’s on WebPages to anchor tags. The extension worked pretty well, but I had a hard time fixing bugs because of scenarios that I hadn’t planned for, like messing up certain websites such as Google Image Search. HippoLink was kind of a test for me. The core part of the extension was bought from a developer at fiverr.com. The test I faced was, whether or not I could have someone code boring pieces of code for me, for a very limited amount of money. I was pretty amazed by the quality of the code written by the programmer, but unfortunately, the test suite I wrote for the developer to pass, was deficient.

NuGetFeed.org
By Summer-Weekation, I started feeling integrated on the eBay team. I met a couple of colleagues who enjoyed coding in their spare time, like me. Brainstorming from these new found friendships ultimately gave birth to the website, NuGetFeed.org. This website is a service on top of NuGet.org, which lets users monitor updates on NuGet packages in their RSS reader. I was amazed by the popularity of the website. We were lucky enough to even get mentions from both Phil Haack and The Morning Brew. The website is still running and serving a lot of .NET developers to this day.

gInfinity
It had been a few months since I had last done a Chrome extension when I came up with the idea for a new extension while at work one day. The question came to me; Why do you still accept clicking the “Next” button in Google search results? Shouldnt it be supported by infinite scrolls like Facebook, Twitter and numerous other sites? Even though Google is experimenting with infinite scroll themselves, I decided to do a quick fix for Chrome myself. The result was gInfinity which turned out to be my most popular Chrome extension so far with over 1,500 users.

smileyapi.dk

A couple of years ago where myrating.dk where still high on my priority list, I made a small service making it possible to generate a smiley image from a CVR number. CVR numbers are the social security number of a company in Denmark and smileys are awarded by the government to all companies handling food. Happy smileys are given for good hygiene and other things, and unhappy smileys are given to companies which needs to fix something. This way the consumers can decide if they want to shop at the company or not. I didn’t really do much work on smileyapi.dk myself this year, but my talented colleague Steffen, helped me by doing a new layout for the site.

startuphq.dk
The idea for my latest project, in 2011, was born from a blog post written by the Danish blogger, Therese Hansen, which listed all Danish IT startups. My former colleague, Rasmus Christensen, invited me to join him on implementing a new website for listing startups. We ended up going live with Version 1 after having spent nearly 4 nights on straight coding. The feature set was limited to the listing functionality, with some fancy Google Maps integration. In the spirit of startups, we used MongoDB for the persistence and hosted the whole thing on AppHarbor. This was a very pleasant experience and even though I aren’t impressed by MongoDB, the gopspatial search is pretty darn awesome. During the next couple of weeks, we implemented a bunch of features like the possibility to find startup related events in your area. We are still adding new features to the site and firmly believe that StartupHQ will have the potential to be a great platform for IT startups and entrepreneurs.

Those are pretty much all of the new projects of 2011. Aside from these, I have also been working on some of my pre-existing sites and projects. The ones worth mentioning are listed below.

myrating.dk
This is pretty much my first web-system implemented using ASP.NET MVC. myrating.dk is a Danish rating site, where users can rate anything from movies to restaurants. I haven’t worked on the site much this year, aside from a new front page and login using Facebook Connect. I could probably implement a lot of new features on myrating.dk, but I’ve been putting too many hours into other projects, aside from my family, to have much time for work lately. Overall, I’m satisfied with the page views on myrating.dk and even though I don’t make a lot of money on it, it’s more than enough to pay for the hosting.

hippovalidator.com
I started implementing hippovalidator.com last year. hippovalidator.com is a website validation system, which can validate a website for different items like markup, performance, spelling and much more. I created the basic features last year, but paused the project to work on a Danish buy/sell site. I had to totally hold off on this idea when starting working at eBay because my project would have been a competitor to another large site that eBay owns called dba.dk. I decided that my design skills weren’t good enough to go live with hippovalidator.com, so I decided to hire a designer to do the graphics. I got in contact with a very talented designer through my work on the buy/sell site and she agreed to design ppovalidator.com as well. The design is pretty almost compete and I’m hoping to get a Version 1 of hippovalidator.com started next year.

When scrolling through this list, I am astonished. I’m impressed with the amount of work I’ve done this year. So what’s up for next year? First, I would like to be able to focus on fewer projects. I’ve been coding multiple projects this year and would like to build a new kick-ass project. hippovalidator.com is one of my key focuses and I would like to be able to release an initial free version in the beginning of 2012. Second, doing both NuGetFeed.org and startuphq.dk in cooperation with others, has taught me that coding with someone else is so much more fun and makes my work more productive. Collaboration makes the final outcomes even better and allows me to focus more easily.

Thanks for sticking around to hear about all of my experiences. Have a great and productive year, folks!

Share this post:

Share to Google Plus

I’ve used mock as long as I remember (pretty much). I’m a big fan of the whole dependency injection movement and make heavily use of IoC containers. Especially constructor injection turns out to be the correct approach for almost every system I’ve worked on. One thing that always bugged me is when creating a new object to run some tests on, is the amount of mocking code I will have to write to create the instance:

var mock = new Mock<IService3>();
mock.Setup(x => x.DoStuff()).Returns(true);
var sut = new ServiceToTest(
    new Mock<IService1>().Object,
    new Mock<IService2>().Object,
    mock.Object);

The above code is a simplified example. Most of my test-hungry classes typically have lots of dependencies injected through their constructors. In the example I only need to set expectations on the mocked IService3, why I simply inject “empty” mocks for the rest of the parameters. Alternative I could inject nulls for the not important parameters, but in my experience, injecting something not null, makes the test more robust to changes in the tested code.

So why is this a problem? It all leads down to the fact that I am lazy. Creating multiple “empty” mocks is boring and every time I add a new parameter to the constructor of the ServiceToTest class, I need to fix one to multiple compile errors in my test project.

I recently discovered that AutoFixture, one of my favorite unit test frameworks, became a lot smarter from version 2.0 and beyond. AutoFixture now accepts plugins, which have opened up for a range of interesting additions to this great framework. A great plugin for all of your Moq users is AutoFixture with Auto Mocking using Moq. Even though the name sounds a bit uncool, the added value is really great! With Auto Mocking my code can be refactored to the following lines:

var fixture = new Fixture().Customize(new AutoMoqCustomization());
var mock = fixture.Freeze<Mock<IService3>>();
mock.Setup(x => x.DoStuff()).Returns(true);
var sut = fixture.CreateAnonymous<ServiceToTest>();

I start by creating a new instance of the AutoFixture Fixture type (line 1). I typically have this line in my test base class anyway. In the same line I tell AutoFixture to use the Auto Moq plugin by creating a new AutoMoqCustomization instance and passing it to the new Customize method on my fixture instance. Fluent APIs are great!

Let’s jump to line 4, where I ask AutoFixture to create a new instance of the ServiceToTest class. AutoFixture does its magic and creates a new instance using reflection. Remember that the ServiceToTest class have a constructor taking three arguments. AutoFixture itself can’t figure out how to create instances of IService1, IService2 and IService3, but because we provided it with the AutoMoqCustomization plugin, which uses Moq for creating those instances. Brilliant!

In my case I actually want to setup some expectations on the IService3 mock, why I use the Freeze feature of AutoFixture (line 3), to tell the framework to use a freezed variable in the fixture. This will bypass the default behavior for creating new instances in AutoFixture.

So what did we accomplish here? Adding parameters to the constructor of ServiceToTest no longer causes compile errors in the tests and furthermore we don’t need to manually add additional “empty” mock parameters. Sweet right?

Share this post:

Share to Google Plus

Since I started writing my NUnit asserts using Assert.That* instead of Assert.Are*, I’ve been hooked on the new syntax. The constraint API makes asserts readable and helps you specifying the expected and actual values at their proper places. One thing that always displeased my eye for perfection, was the R# warning shown when doing multiple asserts on the same value:

R# tries to tell me, that result may be null. That’s just stupid, right? We just asserted, that result is in fact not null. While this definitely is a bug in R#, there is an easy fix for this. Recently I was looking some more at the That-method overloads and found a method, which is probably known but everyone than me. The overload takes a simple bool, making it easy to suppress the R# warning:

What is the difference here? Rather than using the constraints API in NUnit for asserting the value being not null, I simply write a statement translatable to a bool value (result != null). This should make R# happy and to be honest, the code still looks pretty readable to me.

Share this post:

Share to Google Plus