Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created June 14, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/2932939 to your computer and use it in GitHub Desktop.
Save einarwh/2932939 to your computer and use it in GitHub Desktop.
A simple μnit test client, using a multicolored LED light.
namespace Mjunit.Clients.GHI
{
public class LedTestClient : ITestClient
{
private readonly MulticolorLed _led;
private bool _isBlinking;
private bool _hasFailed;
public LedTestClient(MulticolorLed led)
{
_led = led;
Init();
}
public void Init()
{
_led.TurnOff();
_isBlinking = false;
_hasFailed = false;
}
public void OnTestRunStart(object sender,
TestRunEventHandlerArgs args)
{
Init();
}
public void OnTestRunComplete(object sender,
TestRunEventHandlerArgs args)
{
OnAnyTestComplete(sender, args);
}
private void OnAnyTestComplete(object sender,
TestRunEventHandlerArgs args)
{
if (!_hasFailed)
{
if (args.Result.Outcome == TestOutcome.Fail)
{
_led.BlinkRepeatedly(Colors.Red);
_hasFailed = true;
}
else if (!_isBlinking)
{
_led.BlinkRepeatedly(Colors.Green);
_isBlinking = true;
}
}
}
public void OnSingleTestComplete(object sender,
TestRunEventHandlerArgs args)
{
OnAnyTestComplete(sender, args);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment