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

14

28

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 = "[email protected]";
        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) ==========
Felix answered 28/12, 2018 at 18:26 Comment(3)
Seems to be an issue with the unit tests, not with your code. See: github.com/nunit/nunit/issues/2962Justifier
@OlivierJacot-Descombes: (1) the error is with the posted code: the asker has put a Main method where a test method is required, (2) your link refers to NUnit whereas the asker is using MSTest.Leech
Well observed Luke!Justifier
L
14

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

        } 
    }

}
Leech answered 28/12, 2018 at 20:21 Comment(2)
how to write in xUnit?Captain
@Captain chec prkumk answer: install "xunit.runner.visualstudio" nuget packageGrievous
E
30

Have resolved issue with "No test matches the given testcase filter FullyQualifiedName" by running updates to latest version for next packages:

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

For NUnit test project:

NUnit3TestAdapter
Eyeglasses answered 18/3, 2020 at 15:23 Comment(3)
Wow! This fixed my problem, thanks for your response.Mohamed
This is it! Only add Microsoft.NET.Test.Sdk, MSTest.TestAdapter. The last one you will get for free :)Amando
Missing NUnit3TestAdapter was my issue. Thank you!Teddi
E
21

My case is - an old project with NUnit 2.5 opened in a new VS2019 gives the same error.

As NUnit 2.x does not included into VS2019 by default - you need to install it.

Go to Menu -> Extensions -> ManageExtensions

then search for "NUnit 2 Test Adapter"

then install it.

That helped me.

Enfilade answered 3/7, 2020 at 13:27 Comment(0)
L
14

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

        } 
    }

}
Leech answered 28/12, 2018 at 20:21 Comment(2)
how to write in xUnit?Captain
@Captain chec prkumk answer: install "xunit.runner.visualstudio" nuget packageGrievous
H
11

In case of XUnit, I was able to resolve it by adding "xunit.runner.visualstudio" nuget package.

Hill answered 28/12, 2020 at 5:10 Comment(0)
B
10

I was able to resolve the same error message by changing the Default Processor Architecture in Visual Studio 2017. I had to go to Test -> Test Settings -> Default Processor Architecture -> x64. It seems that I had a mismatch between this setting and the Platform target for my test projects.

Burrton answered 18/6, 2020 at 12:42 Comment(1)
Simple as it gets, but worked :)Hennie
O
8

I had the same error. For me, the cause was missing packages:

NUnit.Engine
NUnit3TestAdapter
Ortolan answered 12/12, 2019 at 11:38 Comment(0)
P
4

For Visual Studio 2017, the above error fixed after installing "NUnit3TestAdapter" NuGet package.

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>
Privy answered 13/4, 2021 at 6:27 Comment(0)
C
3

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" />
Collyer answered 19/9, 2019 at 21:48 Comment(0)
S
2

I fixed by adding the nuget package:

MSTest.TestAdapter 
Sigma answered 22/10, 2020 at 0:10 Comment(0)
H
1

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.

Hern answered 11/9, 2019 at 13:26 Comment(0)
B
0

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.

Bergstein answered 12/9, 2019 at 20:5 Comment(0)
C
0

Please set Default Process Architecture to X64. Once it is set you will be run tests. Test > Test Setting > Default Process Architecture > X64

Clamber answered 5/10, 2021 at 17:5 Comment(0)
M
0

I have the same issue. The problem for me was in the App.config.

If I exclude the App.config from the project the tests run!

In my case a section was not defined in configSections and the only visible consequence is that tests doesn't run

Meister answered 4/4, 2022 at 13:1 Comment(0)
C
0

Missing [TestClass] attribute on the Class can cause this also

Caz answered 29/11, 2022 at 8:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.