c# - 测试未出现在 Visual Studio 测试资源管理器中

标签 c# visual-studio

我在设置测试时遇到问题。我已经尝试使用控制台 c# 文件进行运行测试的 selenium 测试,但是它没有出现在测试资源管理器中。当我创建单元测试 c# 项目时,它不会运行或显示在测试资源管理器中。做错了什么?

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

最佳答案

这可能有效。我认为您的 TestMethod 需要是public 和非静态的才能出现在 Test Explorer 中。

namespace SeleniumTests1
{
    [TestClass]
    public class SeleniumTest
    {
        [TestMethod]
        public void Main()
        {

关于c# - 测试未出现在 Visual Studio 测试资源管理器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35870418/

相关文章:

c# - Linux 上的 Mono 与 Windows 上的 .NET 相比有多可靠?

mysql - Entity Framework 中的数据库 View 问题

visual-studio - 在Visual Studio中使用命令行

c# - 有没有一种优雅的方法可以将单个事件处理程序附加到 WPF 中的所有预览鼠标事件?

c# - 不确定如何在 C# 中测试一行代码

c# - 数据集的简单线性回归

c++ - Visual Studio : which source file includes a particular library (with "pragma comment")?

c# - 如何对 LINQ to Objects 查询进行分区?

css - @supports 不会在 Visual Studio LESS 文件中转换

visual-studio - 如何确定 Visual Studio 正在运行的服务包?