Skip to content

Instantly share code, notes, and snippets.

public void EvilTest()
{
Console.WriteLine("All is well.");
var blackHole = new StringWriter();
Console.SetOut(blackHole);
Console.WriteLine("Muwahahaha!");
}
public class ExecuteCases : InstanceBehavior
{
public void Execute(Fixture fixture)
{
foreach (var @case in fixture.Cases)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
try
static Listener CreateListener()
{
var runningUnderTeamCity = Environment.GetEnvironmentVariable("TEAMCITY_PROJECT_NAME") != null;
if (runningUnderTeamCity)
return new TeamCityListener();
return new ConsoleListener();
}
static void Message(string format, params string[] args)
{
var encodedArgs = args.Select(Encode).Cast<object>().ToArray();
Console.WriteLine("##teamcity["+format+"]", encodedArgs);
}
static string Encode(string value)
{
var builder = new StringBuilder();
public interface Listener
{
void AssemblyStarted(Assembly assembly);
void CasePassed(PassResult result);
void CaseFailed(FailResult result);
void AssemblyCompleted(Assembly assembly, AssemblyResult result);
}
##teamcity[testStarted name='CalculatorTests.ShouldAdd']
##teamcity[testStdOut name='CalculatorTests.ShouldAdd' out='2+2 should equal 4']
##teamcity[testFinished name='CalculatorTests.ShouldAdd' duration='15']
##teamcity[testStarted name='CalculatorTests.ShouldSubtract']
##teamcity[testStdOut name='CalculatorTests.ShouldSubtract' out='4-2 should equal 2']
##teamcity[testFailed name='CalculatorTests.ShouldSubtract' details='Assert.AreEqual() Failure|r|nExpected: 2|r|nActual: 123|r|n at CalculatorTests.ShouldSubtract() in c:\path\to\CalculatorTests.cs:Line 38']
##teamcity[testFinished name='CalculatorTests.ShouldAdd' duration='15']
##teamcity[messageName key='value' otherKey='otherValue']
TestWithNoParameters
TestWithInterestingParameter
Person: Arthur Vandelay, born on 1/1/1980 12:00:00 AM.
TestWithInterestingParameter
Person: Kel Varnsen, born on 1/1/1978 12:00:00 AM.
TestWithInterestingParameter
Person: Martin Van Nostrand, born on 1/1/1995 12:00:00 AM.
public class CustomConvention : Convention
{
public CustomConvention()
{
Classes
.NameEndsWith("Tests");
Methods
.Where(method => method.IsVoid());
Parameters(method =>
{
//Attempt to find a perfect matching source for N calls.
var parameters = method.GetParameters();
if (parameters.Length == 1)
return FindInputs(method.ReflectedType, parameters.Single().ParameterType);
//No matching source method, so call it once with with zero parameters.
return new[] { new object[] {} };