Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stepping through and debugging code in Unit tests

I have not been able to debug or step through unit test.

Here is my sample test code...

using System; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using DomainModel.Entities; using DomainModel.Abstract; using WebUI.Controllers;  namespace Tests {     [TestClass]     public class PeopleControllerTests     {          static IPeopleRepository MockPeopleRepository(params Person[] people)         {             var mockPeopleRepos = new Moq.Mock<IPeopleRepository>();             mockPeopleRepos.Setup(x => x.People).Returns(people.AsQueryable());             return mockPeopleRepos.Object;         }          [TestMethod]          public void Count_Of_People()         {             IPeopleRepository repository = MockPeopleRepository(                 new Person { Age = 31, Gender = "Male", Name = "Tom" },                 new Person { Age = 25, Gender = "Female", Name = "Sally" },                 new Person { Age = 18, Gender = "Female", Name = "John" }                 );              PeopleController controller = new PeopleController(repository);             var people = controller.List().ViewData.Model;             var peoplelist = people as IList<Person>;             Assert.AreEqual(3, peoplelist.Count);         }      } } 
like image 750
dotnet-practitioner Avatar asked Nov 05 '10 05:11

dotnet-practitioner


People also ask

Can you debug a unit test code?

Debug and analyze unit tests with Test ExplorerYou can use Test Explorer to start a debugging session for your tests. Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test.


1 Answers

When using Microsoft.VisualStudio.TestTools.UnitTesting, go to 'Test' in the main menu of VS 2010, click submenu 'Debug' -> 'tests in current context'.

Right-clicking on the test-code and selecting 'run tests' will never start the debugger, not even when mode = debug.

like image 83
John Avatar answered Oct 15 '22 00:10

John