1

Whenever I create a .NET unit test project and write [TestMethod]'s, I ran through TestExplorer in Visual Studio 2012 or through Continuous Integration.

The problem I have now is, I have to execute the all test methods from a TestProject Dll and capture the test outcome Pass/Fail and any exception.

I know I can run using mstest command line statement, but I have to execute the TestMethods from dll.

namespace SampleTests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void ConnectionTest()
        {
            var webreq = (HttpWebRequest) WebRequest.Create("http://bing.com");
            using(var res = (HttpWebResponse) webreq.GetResponse())
            Assert.AreEqual(res.StatusCode,HttpStatusCode.OK,"HTTP 200 is not received");
        }
    }
}

so How can I load SampleTests.dll and run the test method to get the result

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    I'm afraid it is not possible, see duplicate http://stackoverflow.com/questions/2054994/is-there-an-api-for-running-visual-studio-unit-tests-programmatically – Konrad Kokosa Dec 14 '13 at 00:55
  • As @KonradKokosa there is no API hookups. But you should be able to load the command line program/exe with the command line statement and run it from a dll? Basically this dll is a wrapper for command line program/exe. How you want to run this dll is entirely up to you. I'm not you sure will get Pass/Fail outcomes in a more readable way as when you run through MSTest explorer. May be it might generate a test result file, and then you can load into. – Spock Dec 14 '13 at 01:05
  • @RajaniKanth, Are you the guys who post about ancient Indian and from USA 2 days ago ? – Anirudha Gupta Dec 14 '13 at 04:37

0 Answers0