Beginners' questions in VS

Microsoft Lecturer 0 Reputation points
2023-05-10T09:57:06.9133333+00:00

1.I wrote code, and created a test project on it. I made a "reference" between them. And yet when I run the test the system does nothing. The test explorer shows that there are 3 tests that have not been run but does not execute them. Do you have an idea why?

  1. Similar to 1. in another project, I wrote a test code that uses a class from the program code itself. There is a build error because it does not recognize the class. What should be done?
  2. Is IntelliTest a component that exists in VS? Do I need to download/install it separately? If so, in what way?

We are talking about vs2022 enterprise, and the code is in C#.

Thanks

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
331 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Microsoft Lecturer 0 Reputation points
    2023-05-10T16:34:15.8933333+00:00

    Thanks!

    Here is the code itself:


    using System;

    namespace UtilityLibraries

    {

    public static class StringLibrary

    {

    public static bool StartsWithUpper(this string s)

    {

    if (String.IsNullOrWhiteSpace(s))

    return false;

    return Char.IsUpper(s[0]);

    }

    public static bool StartsWithLower(this string s)

    {

    if (String.IsNullOrWhiteSpace(s))

    return false;

    return Char.IsLower(s[0]);

    }

    public static bool HasEmbeddedSpaces(this string s)

    {

    foreach (var ch in s.Trim())

    {

    if (ch == ' ')

    return true;

    }

    return false;

    }

    }

    }


    And the testing code


    using System;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using UtilityLibraries;

    namespace StringLibraryTest

    {

    [TestClass]

    public class UnitTest1

    {

    [TestMethod]

    public void TestStartsWithUpper()

    {

    // Tests that we expect to return true.

    string[] words = { "Alphabet", "Zebra", "ABC", "Αθήνα", "Москва" };

    foreach (var word in words)

    {

    bool result = word.StartsWithUpper();

    Assert.IsTrue(result,

    $"Expected for '{word}': true; Actual: {result}");

    }

    }

    [TestMethod]

    public void TestDoesNotStartWithUpper()

    {

    // Tests that we expect to return false.

    string[] words = { "alphabet", "zebra", "abc", "αυτοκινητοβιομηχανία",

    "государство",

    "1234", ".", ";", " " };

    foreach (var word in words)

    {

    bool result = word.StartsWithUpper();

    Assert.IsFalse(result,

    $"Expected for '{word}': false; Actual: {result}");

    }

    }

    [TestMethod]

    public void DirectCallWithNullOrEmpty()

    {

    // Tests that we expect to return false.

    string[] words = { String.Empty, null };

    foreach (var word in words)

    {

    bool result = StringLibrary.StartsWithUpper(word);

    Assert.IsFalse(result,

    $"Expected for '{(word == null ? "<null>" : word)}': " +

    $"false; Actual: {result}");

    }

    }

    }

    }