【引言】INTRODUCTION

Welcome to Telerik JustMock
欢迎来到 Telerik JustMock

Telerik JustMock is an easy to use mocking tool designed to help you create better unit tests, faster than ever. JustMock makes it easier for you to create mock objects and set expectations independently of external dependencies like databases, web service calls, or proprietary code.

Telerik JustMock是一个简单易用的模仿工具,旨在帮助您创建更好更快的单元测试。JustMock让创建模拟对象变得更加容易,并且使其不受外部依赖关系(如数据库、 web服务调用或专有代码)的影响。

The JustMock API is completely AAA (Arrange/Act/Assert) oriented thus helping you keep your unit tests well structured, clean and readable. No matter whether you try to mock an interface, a sealed class or a static class, the pattern you use is the same.

JustMock API 是完全面向 AAA (Arrange-准备/Act-动作/Assert-断言)的,因此可以让您的单元测试保持良好的结构、清晰及可读性。无论您尝试模拟一个接口、密封类或静态类,模式都是一致的。

To read more please visit the Telerik JustMock product overview page.

若想了解更多的信息请访问 Telerik JustMock 产品概述页面。

JustMock Lite is the free open source version of JustMock and it is available from www.nuget.org. For more informaiton about differences between the two versions in regard to supported features visit the Commercial vs Free Version comparison article.
是 JustMock 的免费开源版本,可以在 www.nuget. org 上找到。目前有商业版和免费版,关于两个版本在支持特性方面的差异的更多信息,请访问商业版和免费版比较文章。

What Is Mocking and Why Do I Need It?
什么是Mocking ,为什么我们需要Mocking ?

Mocking is a concept in unit testing where real objects are substituted with fake objects that imitate the behavior of the real ones. Mocking is done so that a test can focus on the code being tested and not on the behavior or state of external dependencies.

Mocking 是单元测试中的一个概念,它先生产一个假对象用于模仿真实对象行为,然后用这个假对象去替换真实对象。Mocking 这样做是为了使测试能够专注于被测试的代码,而不是外部依赖因素。

For example, if you have a data repository class that runs business logic and then saves information to a database, you want your unit test to focus on the business logic and not on the database. Mocking the “save” calls to your database ensures your tests run quickly and do not depend on the availability or state of your database. When you’re ready to make sure the “save” calls are working, then you’re moving on to integration testing. Unit tests should not cross system boundaries, but integration tests are allowed to cross boundaries and make sure everything works together (your code, your database, your web services, etc.).

例如,如果您有一个数据存储库类,该类运行业务逻辑,然后将信息保存到数据库中,那么您希望单元测试侧重于业务逻辑,而不是数据库。模仿对数据库的“save”调用可以确保测试快速运行,并且可以不在意数据库是否可用。当您准备好确保“save”调用正常工作时,就可以进行集成测试了。单元测试不应该跨越系统边界,但是集成测试允许跨越边界,并确保一切(代码、数据库、 web 服务等等)都在一起运行。
What Can Be Mocked?
什么可以被Mocked?

Mock objects can be created and maintained manually, but this is a time consuming and ultimately unproductive approach. A tool like Telerik JustMock allows you to focus on writing tests and forget about the mocking details. Mock objects are created automatically in memory when the tests run based on your simple configuration in the unit test. There are no “physical” mock objects that have to be maintained as your project changes.

你可以手动创建和维护模拟对象,但这是一种耗时且低效率的方法。像 Telerik JustMock 这样的工具可以让你专注于编写测试,而不必在意mocking中的细节。当测试基于单元测试中的简单配置运行时,模拟对象将在内存中自动创建。在项目更改时,不必维护的“物理”模拟对象。

JustMock allows you to mock everything from interfaces, virtual and abstract methods and properties to sealed classes, non-virtual methods and properties, static classes, methods and properties, even those from mscorlib like DateTime, File, FileInfo, etc. All these can be mocked without a single change of your production code.

JustMock 允许你模仿接口,虚拟和抽象的方法和属性到密封类,非虚拟的方法和属性,静态类,方法和属性,甚至那些来自像 DateTime,File,FileInfo 等。所有这些都可以在不更改生产代码的情况下进行模拟。
Final and Static Mocking
Final 和 Static Mocking

Unlike other mocking frameworks, JustMock lets you mock:

不像其他的 mocking 框架,JustMock 允许你mock以下对象:
  • Sealed classes: call methods of sealed classes even with internal
    constructors. Sealed classes
使用内部构造函数调用 Sealed classes 的方法
  • Static classes, methods, properties: create mocks of static classes,
    set expectations for static method and property calls, verify static
    method calls.
静态类、方法、属性: 创建静态类的模拟,设置静态方法和属性的值,验证静态方法的调用
  • Final methods or properties: assert final methods, overloads, out and ref arguments
Final方法或属性: assert Final 方法、重载及out和ref参数
Features At A Glance
功能一览
  1. Test objects and behaviors independently - fake any dependencies like databases, web service calls, proprietary code
 独立地测试对象和行为————伪造任何依赖关系,如数据库、 web 服务调用、专有代码
  • Mock everything
    –interfaces
    –virtual and abstract methods and properties
    –LINQ queries
    –sealed classes
    –static classes, methods, and properties
    –non-virtual methods and properties
    –non-public members and types
    –mscorlib members
    –DLL imports
Mock 任何对象:接口,虚拟、抽象方法和属性,LINQ查询,密封类,静态的类、方法和属性,非虚拟方法和属性,非公共成员和类型,mscorlib成员,DLL 导入
  • Clean Arrange/Act/Assert syntax - keep your unit tests clean and
    readable
清楚Arrange/Act/Assert语法————可以保持单元测试的清晰和可读性
  • Strongly typed fluent interface - no magic strings, compile time
    checks, refactoring support
 强类型的fluent interface————没有magic strings,编译时检查,重构支持
  • Loose mocks, Partial mocking, Recursive/nested mocking, Sequential
    mocking
 松散模拟,部分模拟,递归/嵌套模拟,顺序模拟
  • Fast and lightweight - custom dynamic proxy library meets mocking
    needs only
快速和轻量的————自定义动态代理库只需要mocking
  • Support for Visual Studio - JustMock supports Visual Studio 2019,
    2017, 2015, and older
 对 Visual Studio-JustMock 的支持 Visual Studio 2019、2017、2015或更老版本
  • Support of Microsoft SharePoint and Microsoft Entity Framework
    mocking
支持mocking SharePoint 和 EF
支持 CI/CD、构建工具、代码覆盖工具、分析器、单元测试插件以及其他与 Azure 管道的集成。阅读如何集成 JustMock 和 Azure pipes MSBuild-集成 JustMock 和 MSBuild 任务。阅读如何将 JustMock 与 MSBuild 集成。在 Jenkins 构建中集成 JustMock。阅读如何将 JustMock 与 Jenkins CI 集成。TeamCity-在 TeamCity 构建中集成 JustMock。阅读如何将 JustMock 与 TeamCity 集成。支持 NCover 1.3.3、1.5.8和3.4.6。JetBrains dotTrace-JustMock 支持 JetBrains dotTrace 3.1及以上版本。PostSharp-版本2.1.2.8及以上
Getting Started with Telerik JustMock
从 Telerik JustMock 开始

To learn how to install and work with Telerik JustMock, visit the following resources:

要学习如何安装和使用 Telerik JustMock,请访问以下资源:
安装和设置,将 Telerik JustMock 添加到测试项目中,JustMock API 基础
Free Version
免费版

The Telerik JustMock is a free open source mocking framework. Feel free to review the Telerik JustMock Lite License Agreement to get acquainted with the full terms of use.

是一个免费的开源模拟框架。请随时查看 Telerik JustMock Lite 许可协议,以熟悉完整的使用条款。
Trial Version and Commercial License
试用版和商业许可证

The Telerik JustMock is a commercial mocking framework. You are welcome to explore its full functionality and get technical support from the team when you register for a free 30-day trial. To use it commercially, you need to purchase a license. Feel free to review the Telerik JustMock License Agreement to get acquainted with the full terms of use.

Telerik JustMock 是一个商业模拟框架。当您注册时有30天免费试用期,欢迎您探索它的全部功能,并我们团队提供技术支持。如用于商用,你需要购买许可证。请随意阅读 Telerik JustMock 许可协议,了解使用条款的全部内容。
Support Options
支持方案

For any issues you might encounter while working with Telerik JustMock or JustMock Lite, use any of the available support channels:

  • License holders and active trialists can take advantage of our outstanding customer support delivered by the developers building the library. To submit a support ticket, use the dedicated support system.
  • Our forums are part of the free support you can get from the community and from the team on all kinds of general issues.
  • Our feedback portal provides information on the features/bugs in discussion and also the planned ones for release.
对于在使用 Telerik JustMock 或 JustMock Lite 时可能遇到的任何问题,请使用任何可用的支持渠道:
-许可证持有人和主动实验可以让我们提供更好的支持去使开发人员构建库。提交一个支持票,使用专用的支持系统。
-我们的论坛的一部分是免费支持的,你可以从社区和团队了解各种各样的问题。
-我们的反馈门户提供的信息在features/bug上,当然也讨论和计划发布。
Learning Resources
学习资料

Learning Resources

Next Steps
下一步

Installation and Setup

安装和设置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值