【问题标题】:C# selenium - SetUp - test nameC# selenium - 设置 - 测试名称
【发布时间】:2018-06-30 05:51:38
【问题描述】:

尝试在 SetUp 中获取测试的名称,我得到:“AdhocTestMethod”...

[SetUp]
public void SetUpFunc()
{
    var asd = TestContext.CurrentContext.Test.Name;
}

[Test(Description = "testingSetup")]
public void TestName123()
{
    Assert.IsTrue(false);
}

我正在使用 NUnit 2.6.3

【问题讨论】:

    标签: c# automated-tests nunit


    【解决方案1】:

    我认为您的设置有问题。对我来说效果很好。

    using NUnit.Framework;
    using System;
    
    namespace UnitTestProject1
    {
        public class Tests
        {
            [SetUp]
            public void SetUpFunc()
            {
                var asd = TestContext.CurrentContext.Test.Name;
                Console.WriteLine($"Setup: {asd}");
            }
    
            [Test(Description = "testingSetup")]
            public void TestName123()
            {
                var asd = TestContext.CurrentContext.Test.Name;
                Console.WriteLine($"Test: {asd}");
                Assert.IsTrue(false);
            }
        }
    }
    

    打印出来

    Setup: TestName123
    Test: TestName123
    

    我已经安装了 NUnit 2.6.3 和 NUnitTestAdapter 2.1.1。

    【讨论】:

      【解决方案2】:

      刚刚发布了一个关于“AdhocTestMethod”搜索customattribute adhoctestmethod的新答案

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-09
        • 2018-05-18
        相关资源
        最近更新 更多