MVC Unit Testing学习笔记

MVC Unit Testing

 

  1.http://www.asp.net/mvc/overview/testing

  2.http://www.asp.net/mvc/tutorials/older-versions/nerddinner/enable-automated-unit-testing

1 Walkthrouth:Using TDD with ASP.NET MVC

1.1 Use VS Unit Testing framework

2 TDD测试原则

  • 每个测试方法对应一个特定要求
  • 不应验证数据库或者其他组件
  • 测试方法名称应当具有说明性

3 编码

  3.1 Assert用法

4 参考资料

  4.1 Using Mocks And Tests To Design Role-Based Objects

  4.2 Building Testable ASP.NET MVC Applications

  4.3 Enable Automated Unit Testing

5 工具

  也请参考: Mock Framework.

5.1 Nunit

  • 下载地址:http://www.nunit.org/

5.2 Ninject

6 一些概念

  6.1 TDD

  • Test-Driven Development
  • 是敏捷开发中的一项核心实践和技术,也是一种设计方法论。 TDD的原理是在开发功能代码之前,先编写单元测试用例代码, 测试代码确定需要编写什么产品代码。

  6.2 IoC

  • 也请参考: DI
  • 控制反转(Inversion of Control,英文缩写为IoC)是一个重要的面向对象编程的法则来削减计算机 程序的耦合问题。控制反转还有一个名字叫做依赖注入(Dependency Injection)。简称DI。

  6.3 DI

  • Dependency Injection

  6.4 Mock Framework.

  • 参考文档: 1947414.html 这里详细说明了各种Mock

    6.4.1 Rhino Mocks

    6.4.2 Moq

    • 是利用诸如Linq表达式树和Lambda表达式等为.NET设计和开发的Mocking库

  6.4.3 Typemock

  6.4.4 Moles

  6.5 NuGet

  • NuGet 是免费、开源的包管理开发工具

7 常见问题

  7.1 1.加载config

8 Learning Goals

  8.1 2.如何使用

    8.1.1 2.1 测试view

    a.检查视图存在

    b.Unit test MVC views using Razor Generator

    c.关于视图的单元测试

  8.1.3 Controller

    unit test controller that uses Forms Authentication

  8.1.4 Test Action Filter

  8.1.5 Controller Context

  8.1.6 custom Authorize filters

  8.2 2.1 基本开发流程

    a.创建测试类 [TestClass]

    b.初始化法方法 [TestInitialize]

    c,测试方法 [TestMethod]

    d.测试方法中使用断言 Assert class

  8.3 3.需要注意那些问题

    也请参考: TDD测试原则

思维导图源文件下载Mvc Unit Testing(请使用MindManager打开)

原文地址:https://www.cnblogs.com/kids/p/learnunittest.html