I'm trying to follow Roy Osherove's UnitTests naming convention, with the naming template: [MethodName_StateUnderTest_ExpectedBehavior].
Following this pattern. How would you name a test calling a constructor?
[Test]
public void ????()
{
var product = new Product();
Assert.That(product, Is.Not.Null);
}
Constructor_WithoutArguments_Succeeds
I don't know how you would call this unit test but I strongly suggest you avoid writing it as there's nothing on earth to make the assert fail. If the constructor succeeds the CLR guarantees you a fresh instance which won't be null.
Now if the constructor of your object throws an exception under some circumstances you could name it like this:
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Product_Constructor_ShouldThrowIfNullArgumentSupplied()
{
new Product(null);
}
So two possible cases for the code you are testing:
No need to test the first.
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