Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is summary necessary in unit test method

Since the naming of a unit test method makes its purpose more meaningful, is it necessary to add a summary to a unit test method?

Example:

/// <summary>
/// Check the FormatException should be thrown when a give country data line contains a invalid number.
/// </summary>
[TestMethod]
public void FormatException_Should_Thrown_When_Parse_CountryLine_Containing_InvalidNumber()
{
  ...
}
like image 917
Ji Yalin Avatar asked Sep 14 '09 14:09

Ji Yalin


People also ask

What should a unit test include?

A unit test typically features three different phases: Arrange, Act, and Assert (sometimes referred to as AAA). For a unit test to be successful, the resulting behavior in all three phases must be in line with expectations.

What do you have to avoid in tests in unit testing?

Avoid Test Interdependence You, therefore, cannot count on the test suite or the class that you're testing to maintain state in between tests. But that won't always make itself obvious to you. If you have two tests, for instance, the test runner may happen to execute them in the same order each time.

What are the three parts of a unit test?

The AAA (Arrange-Act-Assert) pattern has become almost a standard across the industry. It suggests that you should divide your test method into three sections: arrange, act and assert. Each one of them only responsible for the part in which they are named after.

Should unit tests be documented?

Unit tests should aim to be self descriptive, but there will always be cases where this goal cannot be achieved and thus description of what has been written is due. In other words, try to make your unit tests so they don't need documentation, but if they need it, write it!


1 Answers

I actually prefer to use the DescriptionAttribute over a summary tag. The reason being that the value of the Description attribute will show up in a results file. It makes failures easier to understand when you're just looking at a log file

[TestMethod,Description("Ensure feature X doesn't regress Y")]
public void TestFeatureX42() {
  ..
}
like image 53
JaredPar Avatar answered Sep 19 '22 17:09

JaredPar