Are you using Canary tests for complex test?

SneWs's picture

If not, you should, and here is why, Canary tests is an internal test of your test setup and should be used when you have a complex setup method. The Canary is a internal test of your test setup.

A great example of when a Canary tests should be used, you have some sort of dependency injection with configuration files, and after refactoring you might have changed some names etc invalidating your wiring configuration.

Here is a quick example in C# using MSTest:

[TestClass]
public class MyTests
{
    [TestInitialize]
    public void TestInitialize()
    {
        // Enable the commented out line and see your CanaryTest fail.
        //throw new InvalidOperationException();
    }

    [TestCleanup]
    public void TestCleanup()
    { }

    [TestMethod]
    public void CanaryTest()
    {
        Assert.IsTrue(true);
    }

    [TestMethod]
    public void TestAddition()
    {
        // Let's do some bad Math to make the test fail!
        Assert.AreEqual(5, 2 + 2);
    }
}

In my opinion, Canary tests are a excellent way to get quick feedback if tests fails due to a failing setup or if it's the actual test itself that fails.

Post new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
© 2008 - 2012 Marcus Grenängen. Drupal theme by Kiwi Themes.