TestContext 属性为空 [英] TestContext property is null

查看:23
本文介绍了TestContext 属性为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从运行测试的地方获取当前的测试目录.我正在使用的代码

i have been tryign to get current test directory from where tests are running. code that i m using

[TestFixture]
    public class ValidatePDF
    {
        public NUnit.Framework.TestContext TestContext { get; set; }
 [SetUp]
        public void Init()
        {
           string t = TestContext.TestDirectory;
        }
}

TestContext 始终为空.我正在使用 Visual Studio 2017 和 NUnit 3我试过 MS TextContext 但它总是返回 null

TestContext is always null. i m using Visual Studio 2017 , and NUnit 3 i have tried with MS TextContext but it always return null

public Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext { get; set; } 

 [Test]
    public void GetMetaInfo()
    {
        string t = TestContext.TestDir;           
    }

推荐答案

移除 MS TestContext,并使用 NUnit 内置的 TestContext.请注意,它是一个静态属性,因此请访问 CurrentContext 的成员.

Remove the MS TestContext, and use NUnit's built in TestContext. Note that it is a static property, so access the CurrentContext's members.

这篇关于TestContext 属性为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆