What Do You Think About This Smelly Test?
- by panamack
I caught a whiff of a smell eminating from one of my tests, in a scenario akin to the following:
[TestFixture]
public void CarPresenterTests{
[Test]
public void Throws_If_Cars_Wheels_Collection_Is_Null(){
IEnumerable<Wheels> wheels = null;
var car = new Car(wheels);
Assert.That(
()=>new CarPresenter(car),
Throws.InstanceOf<ArgumentException>()
.With.Message.EqualTo("Can't create if cars wheels is null));
}
}
public class CarPresenter{
public CarPresenter(Car car)
{
if(car.Wheels == null)
throw new ArgumentException("Can't create if cars wheels is null);
_car = car;
_car.Wheels.Rolling += WheelsRollingHandler;
}
}
I was struggling to describe what the problem is except that it seems wrong that a CarPresenter should attempt to dictate to a Car whether or not it's Wheels are initialised correctly.
I wondered what pointers people here might give me?