繁体   English   中英

MSTest 测试参数化 - 如何命名测试用例?

[英]MSTest Parameterization of Tests - how do I name the test case?

我希望能够命名我的测试用例。 我怎么做?

[TestClass]
public class RegressionTests
{
    [DataRow(SendProposalRequest.systemError, false, 110, SystemValidations.SystemErrorText)]
    [DataRow(SendProposalRequest.proposalError, false, 22, SystemValidations.PTErrorText)]
    [DataRow(SendProposalRequest.financeError, false, 22, SystemValidations.FTErrorText)]
    [DataRow(SendProposalRequest.noFinance, false, 53, SystemValidations.noFinanceErrorText)]
    [DataRow(SendProposalRequest.annualMileage, false, 22, SystemValidations.annualMileageErrorText)]
    [DataRow(SendProposalRequest.loanAmountBoth, false, 33, SystemValidations.loanAmountBothErrorText)]
    [DataRow(SendProposalRequest.proposalError, false, 22, SystemValidations.PTErrorText)]
    [DataTestMethod]
    
    public void ValidationTests(string requestType, bool valid, int errorCode, string errorText)
    {
        TestSetup.TestSetupMethod(requestType, valid, errorCode, errorText);
    }

我不清楚您的问题是关于命名测试方法还是更改测试名称,因为它出现在 Visual Studio 测试资源管理器中。 我将假设您要更改测试资源管理器中的测试名称,或运行测试时生成的测试结果文件。


DataRowAttribute class 有一个名为“ DisplayName ”的属性,您可以使用它来自定义该测试变体的名称:

[TestClass]
public class RegressionTests
{
    [DataTestMethod]
    [DataRow(SendProposalRequest.systemError, false, 110, SystemValidations.SystemErrorText, DisplayName = "System error")]
    //                                                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...
    public void ValidationTests(string requestType, bool valid, int errorCode, string errorText)

使用它的基本格式是:

[DataRow(arg1, arg2, ... argN, DisplayName = "Your custom name here")]
//                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM