Friday, July 16, 2010

Be more assertive when unit testing (and not when challenging me)

I tweeted this today.
A test without an assert is not a test. It leaves the intended behaviour as completely ambiguous.
Apparently I'm wrong. Some people disagreed. They were mistaken.
Let's examine their arguments.

Argument #1: Name the test method clearly enough and you don't need an assert?

public void Should_not_throw_when_doing_that_thing()
        var obj = new MyObj();
        var result= obj.doThatThing();       

To me this this has a huge gap missing in it. I'm a fan of the AAA pattern when constructing tests. Above we are only doing the Arrange and Act part.  This is why I'm not a fan of the [ExpectedException] attribute. There is no assert within the body of the message. It just doesn't read as I expect to be.

Argument #2: A test can contain no assertions, if you are mocking interactions.

public void WhenDoingSomeThingWithAnotherThingThatWillOccur()
    var someThing = MockRepository.GenerateStub();
    var anotherThing = MockRepository.GenerateStub();

    someThing.Stub(x => x.Do(1)).Return(2);

    new myObj(someThing, anotherThing).Do(1);


Ok this is a good point but when you are interaction testing you are still asserting that a behaviour is true. Its even there in the code.

As you can tell I'm not convinced. Can anyone provide a compelling reason to leave asserts out of tests?

Monday, July 05, 2010

Its more than your job's worth!

Recently I've been tasked with recruiting my replacement for my current employer. My worry is that the team will end up with someone who is just there to pick up a pay-cheque or a bumbling incompetent (yes another one, v funny).  As the position is to lead and support an ASP.Net WebForms app I wanted to test the candidate's ability in ASP.Net WebForms. I presumed that the candidate would jump at the chance of proving their worth prior to an interview.

Here's the test
A dating agency, CandyDate, is running a promotion for its members. 
It will provide some romantic food for one date that is set up for its members.

A date comprises of two people, the organiser and the guest, and a location. 

The Romantic food that the member can choose from is

Belgian Choccies

A member can only set up one date but can be an guest on any number of dates and the food must be chosen.

When an organiser submits his date there is a 1 in 4 chance he will also win one of 2 bottles of champagne.
After the 2 bottles have been won there should be no more chance to win the champagne (as there's none left)

The website is very simple (and trusting) so no authentication is needed. Each of the members have unique firstnames (for simplicity) allegiance 

Please construct a simple website to model this scenario in ASP.Net WebForms (vb or c#). If you do not have VS2008 handy you can use VS2010 express but please target .net 2.0 or 3.5   ( . If you need to use a db please use SQL2005 express or SQLlite. All other dependencies should be shipped with the website.

The "Date Form" will be a link off the main website so please start off with a dummy landing page.

All that is required is that you give the members the ability to enter the details of a date and a message (or page) to say the date has been submitted confirming the arrangements. A special message will be shown if the member has won the champagne.

Please do not leave the pages unstyled but don't spend hours on your colour schemes/fonts either. Simple is fine.

You shouldn't spend more than 2 hours on this test. 
I thought that the test was

  • very simple
  • open-ended to allow some creativity
  • show a rudimentary knowledge of , data access and simple logic.
Of the 12 candidates sent the test I had < 50% completion. I couldn't understand why I was getting so few back. These were keen, pre-screened (yes i used recruiters) prospects apparently. So tonight I made the test public and asked for the feedback on Twitter. Some of the comments were along the lines of:
  • Too vague
  • Too long description
  • Two hours is too long.
This surprised me. I kept things deliberately vague so people could create and yet I gave what I thought was enough information to keep them on the right track. I timed the test and did mine well within the allotted timeframe and in any case is 2 hours a lot of time to invest in your career? For over 50% people it was. I think the time issue is the one that gets me.

So I'm interested, after you've done your cv and after you've seen a job you wanted where do you draw the line at making the effort for your new role? I've never had a problem at launching myself at a tech test. I don't mind spending time on a panel interview. Even in failure I've learnt more about myself by going through the motions of applying for a role.

What is more than a job's worth?