Naming a Test block that just calls a constructor?

I am trying to implement the Roy Osherove UnitTests Naming Convention with a naming pattern: [MethodName_StateUnderTest_ExpectedBehavior].

Following this pattern. What would you call a test that calls the constructor?

[Test] public void ????() { var product = new Product(); Assert.That(product, Is.Not.Null); } 
+4
source share
2 answers

Constructor_WithoutArguments_Succeeds

+10
source

I donโ€™t know what you would call this unit test, but I strongly recommend that you avoid writing it because there is nothing on earth to make the statement fail. If the constructor succeeds, the CLR guarantees you a new instance that will not be empty.

Now, if the constructor of your object throws an exception in some circumstances, you can name it as follows:

 [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void Product_Constructor_ShouldThrowIfNullArgumentSupplied() { new Product(null); } 

So, there are two possible cases for the code you are testing:

  • You get a copy
  • You get an exception

No need to check the first one.

+7
source

Source: https://habr.com/ru/post/1309868/


All Articles