MSpec has this notion of 'Behaves_like'.
e.g. here's the behaviour
Code:
[Behaviors]
public class VehicleThatHasBeenStartedBehaviors
{
protected static IVehicle vehicle;
It should_have_a_running_engine = () =>
vehicle.IsEngineRunning.ShouldBeTrue();
It should_have_a_running_engine = () =>
vehicle.IsEngineRunning.ShouldBeTrue();
It should_be_polluting_the_atmosphere = () =>
vehicle.IsPolluting.ShouldBeTrue();
It should_be_idling = () =>
vehicle.RevCount.ShouldBeBetween(0, 1000);
}
And here's two things in common that use it:
Code:
public class when_a_car_is_started
{
Establish context = () =>
vehicle = new Car();
Because of = () =>
vehicle.StartEngine();
[b] Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;[/b]
protected static Car vehicle;
}
public class when_a_motorbike_is_started
{
Establish context = () =>
vehicle = new Motorbike();
Because of = () =>
vehicle.StartEngine();
[b] Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;[/b]
protected static Motorbike vehicle;
}
(taken from this page:
http://lostechies.com/ja...18/behaviours-in-mspec/)This works fine in. The tests run in TestDriven.net and the R# test runner, and NCrunch.
However, if I enclose the tests in another class, e.g. this:
Code:
public class VehicleSpecs // <<<---- Problems arise when an enclosing class is defined
{
[Behaviors]
public class VehicleThatHasBeenStartedBehaviors
{
protected static IVehicle vehicle;
It should_have_a_running_engine = () =>
vehicle.IsEngineRunning.ShouldBeTrue();
It should_be_polluting_the_atmosphere = () =>
vehicle.IsPolluting.ShouldBeTrue();
It should_be_idling = () =>
vehicle.RevCount.ShouldEqual(1000);
}
public class when_a_car_is_started
{
protected static Car vehicle;
Establish context = () =>
vehicle = new Car();
Because of = () =>
vehicle.StartEngine();
Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;
}
public class when_a_motorbike_is_started
{
Establish context = () =>
vehicle = new Motorbike();
Because of = () =>
vehicle.StartEngine();
Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;
protected static Motorbike vehicle;
}
}[
NCrunch doesn't run the tests. The TestDriven.net and R# test runners do run the tests. NCruch reports:
Quote:This test was not executed during a planned execution run. Ensure your test project is stable and does not contain issues in initialisation/teardown fixtures.
It'd be great to get this fixed as I like to enclose related tests in an enclosed class. Do let me know if I can provide any more information.
Cheers,
Steve.