2

I am using MSTest project to automate my system. The test project work fine. But I need to run the test project in my production with out installing visual studio. So that I am using VSTest.Console.exe command-line.

My Login method as below

    [TestMethod]
    [TestCategory("SmokeTests")]
    public void Can_login_with_Empty_UserName()
    {             
     Login(TestContext.Properties["UserName"].ToString(), TestContext.Properties["Password"].ToString());                
    }

and my vstest.console command as below

vstest.console MyPath\SmokeTests.dll /Tests:Login /Settings: PathToSettingFile\tests.runsettings

when I run this command it will give me "System.NullReferenceException: Object reference not set to an instance of an object." Error

But if I change my method like below

    [TestMethod]
    [TestCategory("SmokeTests")]
    public void Can_login_with_Empty_UserName()
    {            
     Login("Admin", "1234");                
    }

Above code will work properly.

So the problem is

TestContext.Properties["UserName"].ToString()

When I run the test case through Visual Studio no issues. Any idea why /Settings: PathToSettingFile\tests.runsettings cannot load runsettings file running through the vstest.console command. Thank you.

Krishan
  • 169
  • 2
  • 12
  • I found the problem. There is no issue with the above code and VSTest.Console.exe command. I had an issue with my test.runsettings file. There was the wrong comment like below <! --> instead of – Krishan Mar 06 '19 at 08:24

0 Answers0