我无法调试或单步执行单元测试。
这是我的示例测试代码...
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);
}
}
}
最佳答案
使用 Microsoft.VisualStudio.TestTools.UnitTesting 时,转到 VS 2010 主菜单中的“测试”,单击子菜单“调试”->“在当前上下文中测试”。
右键单击测试代码并选择“运行测试”将永远不会启动调试器,即使在模式 = 调试时也是如此。
关于c# - 在单元测试中单步执行和调试代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4103712/