dot*_*ner 47 c# unit-testing mstest visual-studio
我无法调试或单步测试.
这是我的示例测试代码......
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 86
使用Microsoft.VisualStudio.TestTools.UnitTesting时,转到VS 2010主菜单中的"测试",单击子菜单"调试" - >"当前上下文中的测试".
右键单击测试代码并选择"运行测试"将永远不会启动调试器,即使在mode = debug时也是如此.
Grz*_*nio 12
是的你可以,谢谢你:)
要实际打破它们,您需要在调试模式下运行单元测试.
小智 5
另一个解决方案...
您需要运行并附加调试器。
将此行设置在测试中执行的第一行(可能在测试类构造函数中):
System.Diagnostics.Debugger.Launch();
Run Code Online (Sandbox Code Playgroud)
然后当调试窗口打开时,选择 Visual Studio。
| 归档时间: |
|
| 查看次数: |
49000 次 |
| 最近记录: |