Salman
Salman

Reputation: 1286

TestContext property is null

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

Upvotes: 0

Views: 703

Answers (1)

Terje Sandstrøm
Terje Sandstrøm

Reputation: 1991

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

enter image description here

Upvotes: 1

Related Questions