Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tests not appearing in Visual Studio test explorer

I'm having issues setting up my tests. I have tried using a console c# file for my selenium tests which runs the test however it doesn't appear in the test explorer. When I create a unit test c# project it doesn't run or show up in the test explorer. What have done wrong?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SeleniumTests1
{
    [TestClass]
    class SeleniumTest
    {
        [TestMethod]
        static void Main(string[] args)
        {

            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.bing.com/");
            driver.Manage().Window.Maximize();

            IWebElement searchInput = driver.FindElement(By.Id("sb_form_q"));
            searchInput.SendKeys("Hello World");
            searchInput.SendKeys(Keys.Enter);

            searchInput = driver.FindElement(By.Id("sb_form_q"));
            string actualvalue = searchInput.GetAttribute("value");

            Assert.AreEqual(actualvalue, "Hello World");
            driver.Close();
        }
    }
}
like image 752
Peter Avatar asked Mar 08 '16 14:03

Peter


People also ask

How do I add a test to test Explorer Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

How do I enable test in Visual Studio?

Start, pause, and stop. To enable Live Unit Testing, select Test > Live Unit Testing > Start from the top-level Visual Studio menu.

Which is better NUnit or MsTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.


1 Answers

This may work. I think your TestMethod needs to be public and non-static in order for it to appear in Test Explorer.

namespace SeleniumTests1
{
    [TestClass]
    public class SeleniumTest
    {
        [TestMethod]
        public void Main()
        {
like image 86
Steve Wong Avatar answered Oct 13 '22 03:10

Steve Wong