【问题标题】:How to Fix this C# issue No test matches the given testcase filter `FullyQualifiedName =如何修复这个 C# 问题没有测试匹配给定的测试用例过滤器`FullyQualifiedName =
【发布时间】:2019-05-26 12:46:45
【问题描述】:

我是 C# 和 Selenium 的新手,我编写了很多脚本,但是当我编写超过 1 个方法或超过 1 个类的单个方法并且单个类总是运行良好时,就会出现问题。

我已经尝试了互联网上所有可能的解决方案和我自己尝试的解决方案,我在其中创建了一个新项目并复制了除类名、方法名和命名空间之外的主要代码并将其粘贴到新项目中它工作正常这是同样的问题,但我想知道问题到底是什么。

These are the Four Classes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SignUpPageAssignment
{

    public class SignUpDetails
    {
        public static string registerPageReDirect = "login_register";
        public static string signUpUserNameID = "username";
        public static string signUpPasswordID = "password";
        public static string confirmPasswordID = "re_password";
        public static string fullNameID = "full_name";
        public static string signUpEmailID = "email_add";
        public static string signUpUserName = "TouqeerABCDEFGHI";
        public static string signUpPassword = "Password@123";
        public static string confirmPassword = "Password@123";
        public static string fullName = "Touqeer Saleem";
        public static string email = "sabaloch67@gmail.com";
        public static string checkBox = "tnc_box";
        public static string captchaForm = "captcha-form";
        public static string signUpButton = "Submit";

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SignUpPageAssignment
{
public class LoginDetails
   {
       public static string loginUserNameID = "username";
       public static string loginPasswordID = "password";
       public static string loginUserName =   SignUpDetails.signUpUserName;
       public static string loginPassword = SignUpDetails.signUpPassword;
       public static string loginButton = "login";
       public static string redirectToLogin = "Click here to login";

   }
}



using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SignUpPageAssignment
{
class Automation
{
        public void TestMethod1()
        {
            IWebDriver driver = new ChromeDriver();


            driver.Url = "http://adactin.com/HotelApp/";

            // SIGN UP START
                               driver.FindElement(By.ClassName(SignUpDetails.registerPageReDirect)).Click();


            driver.FindElement(By.Id(SignUpDetails.signUpUserNameID)).SendKeys(SignUpDetails.signUpUserName);
            driver.FindElement(By.Id(SignUpDetails.signUpPasswordID)).SendKeys(SignUpDetails.signUpPassword);
            driver.FindElement(By.Id(SignUpDetails.confirmPasswordID)).SendKeys(SignUpDetails.confirmPassword);
            driver.FindElement(By.Id(SignUpDetails.fullNameID)).SendKeys(SignUpDetails.fullName);
            driver.FindElement(By.Id(SignUpDetails.signUpEmailID)).SendKeys(SignUpDetails.email);
            driver.FindElement(By.Id(SignUpDetails.checkBox)).Click();
            driver.FindElement(By.Id(SignUpDetails.captchaForm)).SendKeys("");

            Thread.Sleep(5000);

            driver.FindElement(By.Id(SignUpDetails.signUpButton)).Click();

            //SIGN UP END

            //LOGIN IN START

            driver.FindElement(By.LinkText(LoginDetails.redirectToLogin)).Click();
            driver.FindElement(By.Id(LoginDetails.loginUserNameID)).SendKeys(LoginDetails.loginUserName);
            driver.FindElement(By.Id(LoginDetails.loginPasswordID)).SendKeys(LoginDetails.loginPassword);
            driver.FindElement(By.Id(LoginDetails.loginButton)).Click();

            //LOGIN IN STOP

            //IWebElement result =     driver.FindElement(By.ClassName("reg_success"));


            //Assert.Equals("reg_success", result);

        }
    }
}


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SignUpPageAssignment
{
[TestClass]
public class UnitTest1
{
    public static void Main(String[] args)
    {
        Automation automation = new Automation();

        automation.TestMethod1();

    } 
}
}

我正在制作一个注册自动化脚本,用于注册并在注册后登录

显示的错误是:

[12/28/2018 10:44:11 PM Informational] Executing test method 'SignUpPageAssignment.UnitTest1.Main'
[12/28/2018 10:44:11 PM Informational] Executing test method 'SignUpPageAssignment.UnitTest1.Main'
[12/28/2018 10:44:11 PM Informational] ------ Run test started ------
[12/28/2018 10:44:14 PM Warning] No test matches the given testcase filter `FullyQualifiedName=SignUpPageAssignment.UnitTest1.Main` in C:\Users\touqeer\source\repos\SignUpPageAssignment\SignUpPageAssignment\bin\Debug\SignUpPageAssignment.dll
[12/28/2018 10:44:14 PM Informational] ========== Run test finished: 0 run (0:00:03.6212841) ==========

【问题讨论】:

  • 似乎是单元测试的问题,而不是您的代码。见:github.com/nunit/nunit/issues/2962
  • @OlivierJacot-Descombes:(1)错误在于发布的代码:提问者在需要测试方法的地方放置了 Main 方法,(2)您的链接指的是 NUnit,而提问者正在使用 MSTest。
  • 卢克观察得很好!

标签: c# selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

通过为下一个包运行更新到最新版本解决了“没有测试与给定的测试用例过滤器FullyQualifiedName匹配”的问题:

Microsoft.NET.Test.Sdk
MSTest.TestAdapter
MSTest.TestFramework

对于 NUnit 测试项目:

NUnit3TestAdapter

【讨论】:

  • 哇!这解决了我的问题,感谢您的回复。
  • 就是这样!仅添加 Microsoft.NET.Test.Sdk、MSTest.TestAdapter。最后一个你将免费获得:)
【解决方案2】:

我的情况是 - 在新 VS2019 中打开的旧项目 NUnit 2.5 给出了相同的错误。

由于 NUnit 2.x 默认不包含在 VS2019 中 - 您需要安装它。

转到菜单 -> 扩展程序 -> ManageExtensions

然后搜索“NUnit 2 测试适配器

然后安装它。

这对我有帮助。

【讨论】:

    【解决方案3】:

    您不使用Main 方法来运行测试。

    相反,在要作为测试运行的方法上添加[TestMethod] 注释。测试运行器将负责创建测试类的实例并调用这些方法。

    带有[TestMethod] 注释的方法必须是publicvoid,不能是static,并且不应带参数。即使您将[TestMethod] 放在您的Main 方法上,测试也可能不会运行。

    你的UnitTest1 类应该是这样的:

    namespace SignUpPageAssignment
    {
        [TestClass]
        public class UnitTest1
        {
            [TestMethod]
            public void TestMethod1()
            {
                Automation automation = new Automation();
    
                automation.TestMethod1();
    
            } 
        }
    
    }
    

    【讨论】:

    • xUnit怎么写?
    • @user1735921 检查 prkumk 答案:安装“xunit.runner.visualstudio”nuget 包
    【解决方案4】:

    我有同样的错误。对我来说,原因是缺少包:

    NUnit.Engine
    NUnit3TestAdapter
    

    【讨论】:

      【解决方案5】:

      我能够通过changing the Default Processor Architecture in Visual Studio 2017 解决相同的错误消息。我必须去测试 -> 测试设置 -> 默认处理器架构 -> x64。我的测试项目的这个设置和平台目标似乎不匹配。

      【讨论】:

        【解决方案6】:

        如果是 XUnit,我可以通过添加“xunit.runner.visualstudio”nuget 包来解决它。

        【讨论】:

          【解决方案7】:

          我的是 System.Runtime 包的问题。由于某种原因,它被降级为旧版本。我撤消了此版本控制更改,现在测试运行程序工作正常。

            <package id="System.Runtime" version="4.3.1" targetFramework="net462" />
          

          【讨论】:

            【解决方案8】:

            我通过添加 nuget 包来修复:

            MSTest.TestAdapter 
            

            【讨论】:

              【解决方案9】:

              对于 Visual Studio 2017,上述错误在安装“NUnit3TestAdapter”NuGet 包后得到修复。

              packages.config

              <?xml version="1.0" encoding="utf-8"?>
              <packages>
                <package id="Microsoft.CodeCoverage" version="16.8.0" targetFramework="net461" />
                <package id="Microsoft.NET.Test.Sdk" version="16.8.0" targetFramework="net461" />
                <package id="NUnit" version="3.12.0" targetFramework="net461" />
                <package id="NUnit3TestAdapter" version="3.13.0" targetFramework="net461" />
                <package id="Selenium.Support" version="3.141.0" targetFramework="net461" />
                <package id="Selenium.WebDriver" version="3.141.0" targetFramework="net461" />
                <package id="Selenium.WebDriver.ChromeDriver" version="89.0.4389.2300" targetFramework="net461" />
              </packages>
              

              【讨论】:

                【解决方案10】:

                包含 costura.fody 的 nuget 包为我破坏了 xunit 和 nunit 测试,在 Visual Studio 2017 的输出中给了我这个警告

                D:\Desktop\Code Projects\Product\App\Reporting UI\bin\x64\Debug\Report Generator.exe 中没有测试与给定的测试用例过滤器 FullyQualifiedName=Company.Product.Project.UnitTests.TestTestTest 匹配

                在 Visual Studio 2019 16.3.0 预览版中,我什至没有在输出窗口中看到它。

                删除 costura 后,我的单元测试再次运行。

                【讨论】:

                  【解决方案11】:

                  我有一个稍微不同的问题——在我的项目中,我需要一个特殊的配置来运行单元测试,因为我使用 ILMerge 并且在库类的版本之间发生冲突,当一个被直接引用而一个被 ILMerged进入我的测试代码(据我所知,“内部化”应该可以防止这种情况发生,但事实并非如此)。

                  就我而言,我在尝试在“调试”配置下运行测试时遇到此错误。切换到我的自定义测试配置,现在我很好。其他人可能有类似的问题,他们需要处于“调试”模式,但在 VS 中设置为发布配置。

                  【讨论】:

                    【解决方案12】:

                    请将默认进程架构设置为 X64。设置后,您将运行测试。 测试 > 测试设置 > 默认进程架构 > X64

                    【讨论】:

                      猜你喜欢
                      • 2020-08-12
                      • 1970-01-01
                      • 1970-01-01
                      • 2020-09-13
                      • 1970-01-01
                      • 2021-10-11
                      • 1970-01-01
                      • 2020-05-20
                      • 1970-01-01
                      相关资源
                      最近更新 更多