如何修复此 C# 问题 没有测试与给定的测试用例筛选器“完全限定名称 =.



我是C#和Selenium的新手,我几乎制作了许多脚本,但是当我制作多个方法或多个类时会出现问题 单一方法和单个类总是运行良好。

我已经尝试了

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

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:UserstouqeersourcereposSignUpPageAssignmentSignUpPageAssignmentbinDebugSignUpPageAssignment.dll
[12/28/2018 10:44:14 PM Informational] ========== Run test finished: 0 run (0:00:03.6212841) ==========

通过运行更新到下一个软件包的最新版本,解决了"没有测试与给定的测试用例过滤器完全限定名称匹配"的问题:

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

对于 NUnit 测试项目:

NUnit3TestAdapter

我的情况是 - 在新的VS2.5中打开的带有NUnit2019的旧项目给出了相同的错误。

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

转到菜单 -> 扩展 -> 管理扩展

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

然后安装它。

这对我有帮助。

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

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

带有[TestMethod]注释的方法必须publicvoid,不得static,也不应接受任何参数。 即使您[TestMethod]放在Main方法上,测试也可能不会运行。

以下是您的UnitTest1类的外观:

namespace SignUpPageAssignment
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Automation automation = new Automation();
            automation.TestMethod1();
        } 
    }
}
<</div> div class="one_answers">

对于XUnit,我能够通过添加"xunit.runner.visualstudio"nuget包来解决它。

我能够通过更改Visual Studio 2017中的默认处理器体系结构来解决相同的错误消息。我必须转到测试 -> 测试设置 ->默认处理器体系结构 -> x64。此设置与测试项目的平台目标之间似乎不匹配。

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

NUnit.Engine
NUnit3TestAdapter

> 对于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>

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

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

我通过添加 nuget 包来修复:

MSTest.TestAdapter 

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

没有测试与给定的测试用例筛选器匹配 完全限定名称=公司.产品.项目.单元测试.测试 在 D:\桌面\代码项目\产品\应用\报告 UI\bin\x64\调试\报告生成器.exe

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

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

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

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

请将默认进程体系结构设置为 X64。设置完成后,您将运行测试。测试>测试设置>默认进程体系结构> X64

我有同样的问题。对我来说,问题出在应用程序配置中。

如果我从项目中排除 App.config,测试就会运行!

就我而言,配置节中没有定义一个部分,唯一可见的后果是测试无法运行

类上缺少[TestClass]属性也可能导致这种情况

最新更新