I have a base test calss with a testInitialize method which invokes the unit method I want to test.
In one of the tests I am expecting an exception but since the test initialize method is invoking the unit of execution the exception is thrown and I feel that it never reaches my child classes test method to be confirmed and therefor my test fails.
base test class:
public abstract class EdinburghZoneToCmsZoneMapperTestBase
{
protected ZoneCmsBlob _zoneCmsBlob { get; private set; }
protected ZoneGeoJsonFeatureProperties _zoneFeatureProperties;
[TestInitialize]
public void BaseInitialize()
{
_zoneCmsBlob = EdinburghZoneToCmsZoneMapper.Map(MakeZone());
}
protected virtual ZoneGeoJsonFeatureProperties MakeZone()
{
return new ZoneGeoJsonFeatureProperties
{
Name = "1"
};
}
}
child test class:
[TestClass]
public class WhenZoneIdIsEmpty: EdinburghZoneToCmsZoneMapperTestBase
{
protected override ZoneGeoJsonFeatureProperties MakeZone()
{
return new ZoneGeoJsonFeatureProperties
{
Name = string.Empty
};
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ThrowsException()
{
Assert.IsTrue(string.IsNullOrWhiteSpace(_zoneFeatureProperties.Name));
}
}
system under test:
public static class EdinburghZoneToCmsZoneMapper
{
public static ZoneCmsBlob Map(ZoneGeoJsonFeatureProperties zoneFeature)
{
if (string.IsNullOrWhiteSpace(zoneFeature.Name))
throw new ArgumentException("Zone name cannot be empty");
throw new NotImplementedException();
}
}
Aucun commentaire:
Enregistrer un commentaire