Search This Blog

Monday, 27 June 2011

Screw Unit – Teamcity Integration

I had to setup up client side tests to run for my team on Teamcity. I initially thought I should use rake to do this, but then I had to leverage the fact that my team is comfortable with the .Net stack and not so much with Ruby. At this point I just thought i should use a unit test to run my screw unit test via Watin in a browser. This idea is available in a lot of other blogs for QUnit tests. The unit test opens the suite.html , parses the file and reports if the test failed or passed.This works fine. But then when a test failed I had to either look at the logs of the build or had to navigate to the Url, this feedback was ok but not great

I tried to write a teamcity test runner for screw unit which will send messages to TeamCity , but this was hard work and the effort involved was simply too much

If not real time feedback from a test runner, at least seeing the suite.html as a tab on my build would be good.. so I just pushed the artifacts for the build to include the Screw Unit test pack and set up a new tab in TeamCity server config file (main.config file) called Screw Unit Report. This tab would open the html file for the tests from the artifacts. So now I have TeamCity showing the Screw Unit suite as a tab, that's better, the only thing is when you click on the tab it runs the tests every time, but that's not such a big deal really Smile. The effort involved in setting this up was 30 minutes. (I already knew how to setup tabs in TeamCity )

So to summarize

1. Write a unit test runner which will use Watin to open the Screw Unit test suite.html file.

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Diagnostics;
   4: using System.IO;
   5: using System.Linq;
   6: using System.Threading;
   7: using MbUnit.Framework;
   8: using NHamcrest.Core;
   9: using WatiN.Core;
  11: namespace Tests
  12: {
  13:     [TestFixture]
  14:     [Timeout(600)]
  15:     public class TestRunner
  16:     {
  17:         private FireFox browser;
  19:         [SetUp]
  20:         public void SetupBrowser()
  21:         {
  22:             browser = new FireFox();
  23:         }
  24:         /// <summary>
  25:         /// Tests that ScrewUnit tests pass
  26:         /// </summary>
  27:         [Test]
  28:         [Category("ScrewUnitTests")]
  29:         public void RunAllTestsFromSuite()
  30:         {
  31:             var screwUnitTestFile = Path.Combine(Environment.CurrentDirectory, @"Javascript\ScrewUnit\tests\spec\suite.html");
  32:             browser.GoTo(@"file:///" + screwUnitTestFile);
  33:             browser.WaitForComplete(5000);
  35:             var resultsDiv = browser.ElementWithTag("h3", Find.ByClass("status"));
  36:             resultsDiv.WaitUntil(() => resultsDiv.Exists && !resultsDiv.Text.ToLower().Contains("Running"), 30000);
  38:             AssertThatTestsHavePassed(resultsDiv);
  39:         }
  41:         private static void AssertThatTestsHavePassed(Element resultsDiv)
  42:         {
  43:             var resultsArray = resultsDiv.Text.Split(new[] { ' ' });
  45:             var numberOfFailures = Int32.Parse(resultsArray.ElementAt(2));
  47:             Assert.That(numberOfFailures, Is.EqualTo(0), string.Format("{0}. Click on the Screw Unit Report Tab to see the details", resultsDiv.Text));
  48:         }
  50:         [TearDown]
  51:         public void TearDownTestRunner()
  52:         {
  53:             browser.Dispose();
  54:             Thread.Sleep(2000);
  55:             var browserProcesses = Process.GetProcesses()
  56:                     .Where(process => process.ProcessName.ToLower().Contains("firefox") && process.StartInfo.UserName.ToLower().Contains("build"));
  57:                     browserProcesses.Each(p => p.Kill());
  58:         }
  61:     }
  62:     public static class Extensions
  63:     {
  64:         public static void Each<T>(this IEnumerable<T> collection, Action<T> action)
  65:         {
  66:             foreach (var item in collection)
  67:             {
  68:                 action(item);
  69:             }
  70:         }
  72:         public static void WaitUntil(this Element element, Func<bool> predicate, int timeout)
  73:         {
  74:             var startTime = DateTime.Now;
  76:             while (!predicate())
  77:             {
  78:                 Thread.Sleep(1000);
  79:                 var now = DateTime.Now;
  81:                 if ((now - startTime).TotalMilliseconds > timeout) throw new TimeoutException("Timed out waiting for condition to become true");
  82:             }
  83:         }
  84:     }
  85: }

2. Push the Screw Unit test suite into the artifacts of your build in the team city configuration of your build

3. Configure the main.config file located at <TeamCity Install Folder>\.BuildServer\configuration\confg to create a new tab.

Run your build and you should be able to see the screwunit report on the build server now

   1: <server>
   3: <report-tab title="Screw Unit Report" basePath="" startPage="tests/spec/suite.html" />
   5: </server>


You could use the screwunit test sample i took from git hub to test this Screw Unit Tests sample

Thursday, 16 June 2011

Step by Step - Cucumber, WatiR and Ruby installation tips

There are few road blocks you hit when you go about the process of installing Cucumber, Watir and Ruby the first time, you have to search all the information and then as you install there are some things that work while some dont , I just thought it may be a good idea to consolidate the information in one place for myself if i do run into this situation of having to install this again. I have tried and tested this thrice and use the same process to install our test agents.

  • Installing Ruby

#Tip – Choosing the version of Ruby installer

Watir is stable with Ruby 1.8.7 so dont carried away and install 1.9.x of ruby , you learn the hard way that it is not going to work properly.

See Http:// for updates on when 1.9.x support will be provided. Go to download the exe and run the installer. I chose the installation folder to be called just ruby as I want to avoid installing multiple versions for now.


  • Ruby Path

Check if "c:\ruby\bin" is included in the path (else run PATH=%PATH%;c:\ruby\bin at the command prompt)

  • Installing the Dev Kit for Ruby

Download .

  1. Click on it to extract files to a folder <DEV-KIT-FOLDER>.
  2. Open a command prompt for the <DEV-KIT-FOLDER>.
  3. Run the command “ruby dk.rb init
  4. Run the command “ruby dk.rb install

Not sure if you need this but run a “gem update system” and it should say Nothing to update :).

  • Installing gems

Now at the command prompt

  1. Run “gem install cucumber”.
  2. Run “gem install watir”
  3. Run “gem install “win32console”
  4. Run “gem install rspec”
  • Installing ANSI con – if you are unable to see colours on your console window when you run a cucumber feature, you may need to install ANSICON
  1. Go to . Download AnsiCon 140.
  2. Extract the files.
  3. Open a command prompt for the folder you have extracted the files in
    cd to x64 folder if you use a 64 bit machine or x86 folder if you use a 32 bit machine
    type "ansicon.exe -i"
    Close the command prompt , open a new one

This should be sufficient to run cucumber features now. In a weeks time I will post a project framework with some useful stuff for ruby / selenium / cucumber which can be downloaded so you can go about building tests quickly

Wednesday, 15 June 2011

ScrewTurn Wiki

I was looking for a some kind of ASP.Net sample site purely to demo some BDD scenarios at work, but then I wanted to do it on a site which is more complex than the usual ASP.Net sample site made of Customer/Order.

I found a couple of Wikis, but the one that caught my eye was ScrewTurn Wiki. First things first it is free under the GPLv2 license (for more details on commercial licenses see Commercial License Help)

The installation took less than a few minutes using the Microsoft Web Platform installer, You install the Wiki in one of two modes file system storage mode or SqlServer storage mode (just use SqlExpress). To choose which mode you want to install. See Installation Help for more details. Apparently you can go with file storage mode and then switch to the SqlServer data storage mode later (Data Migration)

The fact that you can manage the ScrewTurn Wiki using Microsoft WebMatrix is simply brilliant. The ease of use and ability to be able to publish the Wiki is simply useful. You can pretty much configure your hosting details if you wanted to host something on the internet and keep pushing your changes.

Now for Plugins, quite a lot of them seem to be available. There are vast number of navigational, text editing and data provider plugins. In addition to this you can customise different portions of the Wiki using your own providers , this seems like one of those things that was given a great deal of thought. See Custom Providers

I guess I am very impressed by what the Wiki offers, but looking at the features I am actually wondering if a product which was a Wiki is evolving into a CMS? Not sure, cant say I am bothered either, the only reason I raised that concern is the Wiki as is, is pretty simplistic and this is what appealed to me, building too much into could make it bulky and complex. I am just a developer so I cant give an accurate view of what users of the Wiki would want. On the bright side there are some really new features that are coming and that can be leveraged. V4 CTP offers native Azure support which should be good if you wanted to use Cloud based services I guess. See Roadmap for more details

Monday, 13 June 2011

DDD eXchange 2011 Podcasts

Attended this conference on Friday (10/06/2011) and was consolidating the links for the podcasts

Some of my favourites are

  • · Greg Young on Assert.That(We.Understand) – related to TDD
  • · Udi Dahan on Domain Models and Composite Applications
  • · Jim Webber on REST and DDD - REST based APIs
  • · Matthew Wall on REST & APIs in the Guardian's DDD Processes

Podcast Links