Stubbing your way to automated end to end testing in an API first world

Building high quality end to end acceptance tests suites is hard, and creating API stubs (aka mock servers) can be surprisingly time consuming. WireMock.net can help speed this up. E2E testing is hard End to end testing is hard for many reasons, but I think one of the most common is that the developers under estimate how much time to allow for it and then rush the job. Most E2E test harnesess I have worked on, (including several I wrote myself!...

December 4, 2017 · 7 min · 1476 words · Alastair Crabtree

Choose the right return type for WebApi controllers

WebApi controller actions can return a variety of response types: HttpResponseMessage, IHttpActionResult, CLR objects and then the Task based variety of each for async actions. But which one is best? And how do we unit test them? Lets look at each in turn and examine why IHttpActionResult is usually the right choice. Synchronous controllers returning objects The simplest web api controller can directly return the object in question. Say you have a ProductController that is concerned with CRUD operations on Products, it might have a method like the below:...

May 30, 2016 · 4 min · 661 words · Alastair Crabtree

Smoke test windows authenticated sites with Octopus Deploy

After deploying a website don’t assume it succeeded - add automated tests to check everything works. Back in the old days you would open a browser and check your new version of the site works - make sure IIS is running, the app pools starts, your database login credentials are valid etc. A human sanity check is always good - i still do it often - but ideally I want to know during deployment if something simple like that has caused the deploy to break the system....

May 5, 2016 · 4 min · 643 words · Alastair Crabtree

What should I look for when doing a code review?

In addition to my previous post about how to do better code reviews below is a list of specific things to watch out for during code reviews, in no particular order: All the CI builds are green The diff/pull request should be small enough that it is reasonable to review it in under 30min - avoid giant whitespace changes. The entire app build is scripted and available with one click/script CI builds are clearly named and well organised, with separate build/test, deploy and acceptance tests stages Deployment is 100% automated New code does not introduce unnecessary duplication....

March 11, 2016 · 3 min · 428 words · Alastair Crabtree

Tips for running a code Kata

Code katas such as the classic bowling game kata by uncle bob are a good way of fostering TDD best practice in your team. Here, in no particular order, are a few hints for running them I have picked up over the last few months. Start with a subject that everyone knows. For example with the bowling game don’t assume that everyone knows how to play and how to score the game....

February 14, 2016 · 3 min · 467 words · Alastair Crabtree

What type of test is that?

Tests help you ensure your code works, but they come in several shapes and sizes. Here are the four key ones I use, and how to spot the difference. Unit tests AKA: TDD, fast tests, “tests” Usually written by: Developers Time to run one: few ms Time to run suite: few secs - 3m Component under test: one or more related classes/types usually in the same module. Success: You have hundreds of quick running tests that cover 80% of application code....

February 2, 2016 · 2 min · 410 words · Alastair Crabtree