How to Fix this C# issue No test matches the given testcase filter `FullyQualifiedName =

社会主义新天地 提交于 2019-12-12 14:15:13

问题


I am new to C# and Selenium and I have pretty much made a number of scripts but there comes a problem when I make more than 1 method or more than 1 class single method and single class always runs good.

I have tried every possible solution on the internet and my self tried solution in which I made a new project and copied the main code other than class name, method name and namespace and pasted it onto new project it worked fine this is the same issue but I want to know what the problem really is.

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

    } 
}
}

I am making a signup automation script that signups and after signup it logins

The error that is displayed is :

[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) ==========

回答1:


You don't use a Main method to run a test.

Instead, put a [TestMethod] annotation on the methods you want to run as tests. The test runner will take care of creating an instance of your test class and calling these methods.

Methods with the [TestMethod] annotation must be public and void, must not be static and should take no arguments. Even if you put [TestMethod] on your Main method, the test would likely not run.

Here's what your UnitTest1 class should look like:

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

            automation.TestMethod1();

        } 
    }

}



回答2:


Including the nuget package for costura.fody broke both xunit and nunit tests for me, giving me this warning in the output in Visual Studio 2017

No test matches the given testcase filter FullyQualifiedName=Company.Product.Project.UnitTests.TestTestTest in D:\Desktop\Code Projects\Product\App\Reporting UI\bin\x64\Debug\Report Generator.exe

In the Visual Studio 2019 16.3.0 preview, I didn't even get that in my output window.

After removing costura, my unit tests run again.




回答3:


I had a slightly different issue -- in my project, I need a special configuration to run unit tests, as I use ILMerge and was getting a conflict between the versions of library classes, when one was referenced directly and one was ILMerged into my code under test (As far as I know, "Internalize" should prevent this, but it doesn't).

In my case, I got this error when trying to run tests under the "Debug" configuration. Switched to my custom Test configuration and now I'm good. Other people might have a similar issue where they need to be in the "Debug" mode, but are set in VS to be in Release configuration.




回答4:


Mine was an issue with System.Runtime package. It got downgraded for some reason to older version. I undo this versioning change and now test runner is working fine.

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


来源:https://stackoverflow.com/questions/53962823/how-to-fix-this-c-sharp-issue-no-test-matches-the-given-testcase-filter-fullyqu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!