Ji *_*lin 16 c# unit-testing mstest visual-studio
由于单元测试方法的命名使其目的更有意义,是否有必要向单元测试方法添加摘要?
例:
/// <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()
{
...
}
Run Code Online (Sandbox Code Playgroud)
Jar*_*Par 43
我实际上更喜欢在摘要标记上使用DescriptionAttribute.原因是Description属性的值将显示在结果文件中.当您只是查看日志文件时,它会使故障更容易理解
[TestMethod,Description("Ensure feature X doesn't regress Y")]
public void TestFeatureX42() {
..
}
Run Code Online (Sandbox Code Playgroud)
jrc*_*cs3 10
我认为长描述性名称比XML注释更重要.由于单元测试不会成为API的一部分,因此您不需要XML注释.
例如:
[TestMethod]
public void FormatException_Should_Thrown_When_Parse_CountryLine_Containing_InvalidNumber()
{
...
}
Run Code Online (Sandbox Code Playgroud)
比以下更有用:
///<summary>
/// Exception Should Thrown When Parse CountryLine Containing InvalidNumber
///</summary>
[TestMethod]
public void Test42()
{
...
}
Run Code Online (Sandbox Code Playgroud)
XML注释应该用于记录API和框架.
| 归档时间: |
|
| 查看次数: |
7007 次 |
| 最近记录: |