开发者

Naming Unit Tests that just calls a constructor?

I'm trying to follow Roy Osherove's UnitTests naming convention, with the naming templ开发者_JAVA技巧ate: [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:

  1. You get an instance
  2. You get an exception

No need to test the first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜