public class Foo<T>
{
public Foo(Bar bar)
{
if (bar == null) throw new ArgumentNullException("bar");
}
}
public class Foo : Foo<Object>
{
public Foo(Bar bar) : base(bar) { }
}
Basically, I understand that I should unit test the constructor for the Generic Foo. Should I also unit test the constructor for the non-generic version? The reason I ask is because the exception is being thrown at the generic constructor level...
[TestMethod]
[ExpectedExeption(typeof(ArgumentNullException))]
public void GenericFooNullArgumentInConstructor()
{
var foo = new Foo<int>(null);
}
//Is this test necessary?
[TestMethod]
[ExpectedExeption(typeof(ArgumentNullException))]
public void NonGenericFooNullArgumentInConstructor()
{
var foo = new Foo(null);
}
Yes. Without looking at all the implementations, that's the easiest way to verify that your derived classes have maintained the guarantees of your base class. Especially when Bob the intern comes in later and modifies your derived class to do something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With