JustMock Lite (Free Mocking Framework For .net)
3. 帮助文档
商业版和免费版区别概览

MockingContainer
测试类准备:一般来说也是业务类
public class ClassUnderTest
{
private IFirstDependency firstDep;
private ISecondDependency secondDep; public ClassUnderTest(IFirstDependency first, ISecondDependency second)
{
this.firstDep = first;
this.secondDep = second;
} public IList<object> CollectionMethod()
{
var firstCollection = firstDep.GetList(); return firstCollection;
} public string StringMethod()
{
var secondString = secondDep.GetString(); return secondString;
}
} public interface IFirstDependency
{
IList<object> GetList();
} public interface ISecondDependency
{
string GetString();
}
单元测试
[TestMethod]
public void ShouldMockDependenciesWithContainer()
{
// ARRANGE
// Creating a MockingContainer of ClassUnderTest.
// To instantiate the system uder test (the container) you should use the Instance property
// For example: container.Instance.
var container = new MockingContainer<ClassUnderTest>(); string expectedString = "Test"; // Arranging: When the GetString() method from the ISecondDependecy interface
// is called from the container, it should return expectedString.
container.Arrange<ISecondDependency>(
secondDep => secondDep.GetString()).Returns(expectedString); // ACT - Calling SringMethod() from the mocked instance of ClassUnderTest
var actualString = container.Instance.StringMethod(); // ASSERT
Assert.AreEqual(expectedString, actualString);
}
需要说明的是MockingContainer构造函数有一个可选参数AutoMockSettings,其中AutoMockSettings最主要的一个作用的是当ClassUnderTest有多个构造函数时,指定合适的构造函数来实例化对象
当业务类中有一个无参构造函数,一个有参构造函数,在没有设置AutoMockSettings的情况下会默认执行无参构造函数,
可以像下面这样来指定需要的构造函数
AutoMockSettings settings = new AutoMockSettings
{
ConstructorArgTypes = new Type[]{
typeof(IFirstDependency),typeof(ISecondDependency)
}
}; // ARRANGE
// Creating a MockingContainer of ClassUnderTest.
// To instantiate the system uder test (the container) you should use the Instance property
// For example: container.Instance.
var container = new MockingContainer<ClassUnderTest>(settings);
JustMock Lite (Free Mocking Framework For .net)的更多相关文章
- Testing with a mocking framework (EF6 onwards)
When writing tests for your application it is often desirable to avoid hitting the database. Entity ...
- 什么是Mocking framework?它有什么用?
原位地址:http://codetunnel.com/blog/post/what-is-a-mocking-framework-why-is-it-useful 今天我想讲下关于mocking fr ...
- Mocking framework
[译] 什么是Mocking framework?它有什么用? 原位地址:http://codetunnel.com/blog/post/what-is-a-mocking-framework-why ...
- What is a mocking framework? Why is it useful?
Today I want to talk about mocking frameworks and why they are useful. In order to do that I first n ...
- 什么是Mocking framework?它有什么用?(转)
今天我想讲下关于mocking frameworks,并且解释下他为什么有用处.我将给你们展示用和不用mocking framework两种测试方法. 假设我们已经有了一个Driver类: publi ...
- Googletest - Google Testing and Mocking Framework
Googletest - Google Testing and Mocking Framework https://github.com/google/googletest
- 利用Mocking Framework 单元测试Entity Framework
一.前言 在实际编写程序时,往往需要与数据库打交道,在单元测试中直接使用数据库又显得太重,如果可以方便的编写一些测试数据,这样更易于检测功能.如何模拟数据库行为便是本篇的主题.微软有教程说明Moq E ...
- 第一篇:Entity Framework 简介
先从ORM说起吧,很多年前,由于.NET的开源组件不像现在这样发达,更别说一个开源的ORM框架,出于项目需要,以及当时OOP兴起(总不至于,在项目里面全是SQL语句),就自己开始写ORM框架.要开发O ...
- Entity Framework版本历史概览
转自:http://www.cnblogs.com/fecktty2013/archive/2014/09/26/entityframework-overview.html EF版本 .net fra ...
随机推荐
- Drupal 7.31SQL注入getshell漏洞利用详解及EXP
0x00 这个漏洞威力确实很大,而且Drupal用的也比较多,使用Fuzzing跑字典应该可以扫出很多漏洞主机,但是做批量可能会对对方网站造成很大的损失,所以我也就只是写个Exp不再深入下去. 0x0 ...
- MV*模式的个人理解
MV*模式主要解决的问题就是 View代码难以维护的问题. MV*模式将View中的逻辑分离出去,形成一个弱逻辑的易于维护的视图. MV*中的*是Model和View的桥梁,负责保持Model和Vie ...
- svn branch and merge(svn切换分支和合并)详解
下文的实践主要是参考了TortoiseSVN的帮助文档和Subversion的在线文档,Subversion的在线文档:http://svnbook.red-bean.com/en/1.5/svn-b ...
- jquery自定义函数的多种方法
在jquery中自定义函数你会吗?今天抽时间写了几个,个人感觉还不错,喜欢的朋友可以了解下 复制代码 代码如下: //方法定义 $.windowbox = { //定义一个方法aa aa: fun ...
- JQuery Easy Ui dataGrid 数据表格
数据表格 - DataGrid 英文文档:http://www.jeasyui.com/documentation/index.php# 继承$.fn.panel.defaults,使用$.fn.da ...
- 2014 牡丹江区域赛 B D I
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...
- cf251.2.C (构造题的技巧)
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...
- .NET异步编程之回调
C#中异步和多线程的区别是什么呢?异步和多线程两者都可以达到避免调用线程阻塞的目的,从而提高软件的可响应性.甚至有些时候我们就认为异步和多线程是等同的概念.但是,异步和多线程还是有一些区别的.而这些区 ...
- 第九天 iOS音频技术
1. AQRecorder mRecordFormat.mFormatID = inFormatID; if (inFormatID == kAudioFormatLinearPCM) { // if ...
- Java之enumeration(枚举)
enumeration(枚举)是JDK1.5引入的新特性,放在java.lang包中. 1.枚举类方法介绍 package com.enums; public class TestEnum { pub ...