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.