Franco Pettigrosso
Franco Pettigrosso

Reputation: 4288

Can you Have multiple unit test files

I have two unit test files in Visual Studio, for example test1.cs and test2.cs... When I select run all tests, it only runs the test from test1.cs. How can I make visual studio run tests from both test1.cs and test2.cs?

Additional information: If I select a test method from test2.cs, the output will tell me "No tests found to run."

(test2.cs == ADPReportClassTest.cs)

using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EmployeeRefreshTest.tests
{
    [TestClass]
    class ADPReportClassTest
    {
        TestContext TestContext { get; set; }

        [TestMethod]
        [DataSource("System.Data.SqlClient", "Server=Localhost;Database=Test_Employee_Refresh;Integrated Security=Yes", "ADPREPORTCLASS_Tuples", DataAccessMethod.Sequential)]
        public void Checkconstructor()
        {
            string filename = TestContext.DataRow["TestFileName"].ToString();
            Assert.AreEqual(filename, filename);
        }
    }
}

Upvotes: 3

Views: 2151

Answers (1)

Nkosi
Nkosi

Reputation: 247088

In order for the test runner to see all relevant members to be used in testing they must be public. So that would include all test classes, their test methods and any contexts that are needed for data sources.

Update the test accordingly

[TestClass]
public class ADPReportClassTest //<-- public
{
    public TestContext TestContext { get; set; } //<-- public

    [TestMethod]
    [DataSource("System.Data.SqlClient", "Server=Localhost;Database=Test_Employee_Refresh;Integrated Security=Yes", "ADPREPORTCLASS_Tuples", DataAccessMethod.Sequential)]
    public void Checkconstructor() //<-- public
    {
        string filename = TestContext.DataRow["TestFileName"].ToString();
        Assert.AreEqual(filename, filename);
    }
}

Upvotes: 3

Related Questions