Visual Studio 2022 mstest .NETcore - Gives no explanation why it won't run unit tests or how to fix the problem

260 Views Asked by At

PRoj file

Sdk="Microsoft.NET.Sdk" 
"DotNetSeleniumExtras.PageObjects.Core" V="4.3.0" "itext7" V="7.2.5" "Microsoft.Extensions.Configuration" V="7.0.0" "Microsoft.Extensions.Configuration.Json" V="7.0.0" "Microsoft.NET.Test.Sdk" V="17.5.0" "coverlet.collector" V="3.1.2" "MSTest.TestAdapter" V="3.0.2" "MSTest.TestFramework" V="3.0.2" "Selenium.Support" V="4.9.0" "Selenium.WebDriver" V="4.9.0" "Selenium.WebDriver.ChromeDriver" V="112.0.5615.4900" "SeleniumExtras.WaitHelpers" V="1.0.2"
public static void ClassInit(TestContext context)
{
   var _configuration = new ConfigurationBuilder()
       .SetBasePath(Directory.GetCurrentDirectory())
       .AddJsonFile(@"TestData.json", optional: false, reloadOnChange: true)
       .Build();

   if (_configuration != null)
   {
      pageLoadTimeout =    Convert.ToInt16(_configuration["TestDataCollection:PageLoadTimeout"]);
      ePortalUsername = _configuration["TestDataCollection: ePortalUsername"];
      ePortalPassword = _configuration["TestDataCollection: ePortalPassword"];
    }

    if (TestContext != null)
    {
       browser = browser = Convert.ToString(TestContext.Properties["Browser"]);
       url = Convert.ToString(TestContext.Properties["OLSPortalUrl"]);
    }
}

Here's json file

{
  "__comments": "Test data is collection of TestDataInstance. Each instance contains testing   accounts and data",
  "TestDataCollection": [
   {
      "ePortalUserName": "some username",
      "ePortalPassword": "some password",
      "OLSPortalUrl": "http://www-test.someurl.com/",
      "PageLoadTimeout": "40"
   }
  ]
}

Here's my runsettings file

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
     <TestRunParameters>
        <Parameter name="Browser" value="Chrome" />
        <Parameter name="Environment" value="TEST" />
        <Parameter name="OLSPortalUrl" value="http://www-test.paccarfinancial.com/" />
     </TestRunParameters>
</RunSettings>

Test output:

Building Test Projects
========== Starting test run ==========
========== Test run finished: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ==========

Here is my Testclass and TestMethod

[TestClass]
public class Tests : BaseTestClass
{
    [TestCategory("Test"), TestMethod]
    public void PAC041_01_Navigate()
    {            
        if (browser != null && url != null)
        {
            driver = Utility.InitBrowser(browser, pageLoadTimeout);
            Utility.NavigateToUrl(url);
            Assert.AreEqual("Home Page", driver.Title);
            driver.Quit();
        }
    }
}

I tried removing json file and keeping only runsettings file still my tests are not picked up. Since i am on .NET core AppSettings is not supports so I have to use json for the testdata. I am not sure what wrong i am doing here. Can some one please help me with this?

0

There are 0 best solutions below