Question Why Are Unit Tests Not Working?

seagull

New member
Joined
Jul 9, 2017
Messages
1
Programming Experience
Beginner
Hi there!

I am new in town! I will start off with this Visual Studio problem and see where things go from there. Hopefully, I will visit these forums many times to come.

I have a Windows 10 Pro PC here, and the latest build of Visual Studio 2017 Community edition. The problem is that I cannot get the unit tests to work.

I have done a complete uninstall of Visual Studio 2017, then installed the latest build again.

I have created a new solution, with only one project - the C# unit test project. I used the template code, without any modification.

It doesn't do anything when I click the Run All link in Test Explorer panel.

test1.png

test2.png

test3.png

test4.png

This is the code:

C#:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject2
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {

        }
    }
}

The first time I click, it tells me this:

Discover test finished: 0 found

Then I click to run the tests again and it just hangs itself and doesn't say anything. The system is not hanged, nor is Visual Studio. It even says "build succeeded". It's just the output window for the tests that look dead from my view. I even tried to alter the code a bit, to make it pass, like so:
C#:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            int a = 44;

            Assert.AreEqual(a, 44);
        }
    }
}

Still nothing!

What could be the problem? What can I do to try to resolve this? Ultimately, I will be reinstalling the entire PC. But before I do, I would like to see if this can be sorted out.

Thank you!
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,250
Location
Sydney, Australia
Programming Experience
10+
I've never actually created a unit test project without some other project to test. I wonder whether things are getting confused because there's an assumption being made somewhere that there will indeed be a testable project if there's a test project.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,250
Location
Sydney, Australia
Programming Experience
10+
That said, I just created a blank solution, added a unit test project to it and got the same code as you, then right-clicked the code window and selected Run Tests and it successfully ran TestMethod1 and reported the test as passing. Maybe that project is broken, so maybe try creating a new solution and a new project and see if the same thing happens.
 
Top Bottom