简体   繁体   中英

How to add a reference and how to test if is it palindrom using unit test

Firstly I have problem with Visual Studio I cann't add a reference. It says unable to add a reference to project ...

My second question is the testing, i'm not to testing, so could I know the difference between unit test and xunit test, I've seen a xunit is a NuGet package. And I'm not sure If I'm testing right if it's a palindrome.

I've tried to set my Framework to 4.0 I've seen it on SO, so I can add a reference but it didn't work.

namespace PalindromeTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void IsItPalindrom()
        {
            string a = "1221";
            string b = "1221";
            string res = "";
            if (a == b)
            {
                  res =a;
                  bool x = Program.IsItPalindrom(res);
            }



            Assert.IsTrue(x);
        }
    }
}

My method for testing if the word is palindrome:

 private static bool IsPalindrome(string text)
        {
            int min = 0;
            int max = text.Length - 1;

            while (true)
            {
                if (min > max)
                {
                    return true;
                }

                char a = text[min];
                char b = text[max];

                if (char.ToLower(a) != char.ToLower(b))
                {
                    return false;
                }

                min++;
                max--;
            }

When I run the test or all the test I should see tick on the test explorer, but since I can't add a reference it says that program doesnt contain a definition for IsItPalindrom.

A Windows Universal test project cannot reference a .NET Framework assembly. When you create the test project you should choose the Unit Test Project (.NET Framework) template under Visual C#->Test provided tghat your WPF application or class library targets the .NET Framework.

And xUnit has nothing to do with this.

Your projects are incompatible with each other. If your main project's target is netcoreapp -> than your test projects should be netcoreapp.

If your main project's target is netframework -> than your test projects should be netframework too.

But you can add a reference to netstandard library from any of .NET Frameworks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM