您的位置:首页 > 编程语言 > C#

VS2010用C#写单元测试的一些总结

2011-11-01 17:26 211 查看
1.单元测试中一个完整的测试类:

[TestClass]

public class SomeClassTest

{

[TestInitialize()]

[HostType("Moles")]

public void SetUp()

{ }

[TestCleanup()]

[HostType("Moles")]

public void TearDown()

{ }

[TestMethod]

[HostType("Moles")]

[ExpectedException(typeof(NotSupportedException))]

public void MethodTest(){}

}

2.其中的[TestInitialize()]属性表示测试初始化跑的地方,[TestCleanup()]属性表示是每次执行完测试类后清除的东西也就是测试类最后跑的地方,[HostType("Moles")]属性表示的是这个工程中可以加载所有Moles也就是可以Mock很多类中的东西,[ExpectedException(typeof(NotSupportedException))]属性表示Assert也就是论断Exception的一种方式
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: