简体   繁体   中英

Why I can't use the unit test method definied into this unit test class?

I am pretty new in C# and I have the following situation.

I have a Unit Test class named UnitTest1 into a project named UnitTestProject .

In this class I have the following method:

    [TestMethod]
    public void ConnectionMaliciousCodeManager()
    {
        DataModel.MaliciousCodeManager manager = new DataModel.MaliciousCodeManager("DefaultConnection");

        try
        {
            manager.openConnection();
        }
        catch (Exception ex)
        {
            Debug.WriteLine("Exception: " + ex.Message);
        }
        finally
        {
            manager.closeConnection();
        }
    }

and it work well.

Now I am doing some refactoring and I have create a new MaliciousUnitTest class into my project and I want to moove the previous method into this new class but now it don't work. This is my entire MaliciousUnitTest class code:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.Collections.Generic;

namespace UnitTestProject
{
    [TestClass]
    class MaliciousUnitTest
    {

        [TestMethod]
        public void ConnectionMaliciousCodeManager()
        {
            DataModel.MaliciousCodeManager manager = new DataModel.MaliciousCodeManager("DefaultConnection");

            try
            {
                manager.openConnection();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception: " + ex.Message);
            }
            finally
            {
                manager.closeConnection();
            }
        }

    }
}

I have no errors but the problem is that when I put the mouse cursor on my ConnectionMaliciousCodeManager() method and if I try to do right click and click on Run Tests nothing happens.

If I go into the Visual Studio Text Explorer section I can't find the ConnectionMaliciousCodeManager() .

Why? What am I missing? What have I to do to use the test methods that I define into my new MaliciousUnitTest class?

Tnx

Make the test class have public visibility. Not specifying the visibility means your test class is internal , which Visual Studio is unable to see.

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