TestContext property is null

為{幸葍}努か 提交于 2019-12-02 19:59:28

问题


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 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;           
    }

回答1:


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



来源:https://stackoverflow.com/questions/58768812/testcontext-property-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!