Live Unit Testing
Live Unit Testing
相对于传统的Unit Test,VS2017 带来了一个新的功能,叫Live Unit Testing,从字面意思理解就是实时单元测试,在实际的使用中,这个功能就是可以在编写代码的时候进行实时的background的单元测试.
在体验之前,有几点注意事项是需要了解的:
1.目前 live unit tesing仅仅支持 C#和VB的传统.net版本,不支持.net core,当然,我觉得也不支持其他的语言,这点是暂时让我遗憾的,因为从体验的结果来看,如果能支持其他的语言,无疑是非常非常吸引人的功能.
2.可以和第三方的测试框架结合,不仅仅是MSTEST,我就是用的NUnit,当然XUnit也没有问题.
要想启用测试,本身来讲是非常简单的.
只需要在Test 菜单 启用Live Unit Testing就可以了.

如果你使用NUnit的话,需要安装Nunit test adpater Install-Package NUnite3TestAdapter
测试的过程就比较简单了.
我们可以按照我们的需要,写一些需要测试的内容,然后创建TestMethod,就可以进行测试,与传统测试不同的是,所有的单元测试,不需要手工触发,可以自动进行.
public class Item
{
public string Name { get; set; }
public decimal Price { get; set; }
}
public class ShoppingCart
{
public int UserID { get; set; }
public string UserName { get; set; }
public DateTime LastUpdated { get; set; }
public List<Item> Items { get; set; }
public decimal Total { get { return Items.Sum(i => i.Price); } }
}
然后我们可以创建一个测试的类,并编写测试的方法.

在我们的编写过程中,启动了Live Unit Testing的VS2017 会帮我们进行持续的测试,并根据测试的结果,标注在每一行中.
同样,针对已经完成了单元测试的代码,也会进行实时的标记,如下图所示:

这样,我们可以很清楚的看到整个代码的测试覆盖情况.
而且在整个编码过程中,我们完全不需要停止测试的过程,只要我们进行编码,随时都会进行测试,并显示代码测试的覆盖情况,而且会立即显示代码的错误.
例如:

我们保存以后,马上就有提示,然后紧接着会进行单元测试.然后实时的显示测试失败的情况,如下图:

而且这个错误会同时显示在我们的TestMethod和我们的代码编写中,可以想见,这样的方式,将会极大的提升我们编写代码的效率.
但是这样也带来了一个问题,在我们写代码的过程中,可能不希望所有的单元测试都是这样实时的进行的,这个时候,我们可以简单的进行单个测试文件的排除:

只要在Explorer里面,选择不希望包含的类,直接在右键菜单里面排除就行了.
Live Unit Testing的更多相关文章
- Unit Testing with NSubstitute
These are the contents of my training session about unit testing, and also have some introductions a ...
- [Java Basics3] XML, Unit testing
What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...
- Javascript单元测试Unit Testing之QUnit
body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; } QUnit是一个基于JQuery的单元测试Uni ...
- [Unit Testing] AngularJS Unit Testing - Karma
Install Karam: npm install -g karma npm install -g karma-cli Init Karam: karma init First test: 1. A ...
- C/C++ unit testing tools (39 found)---reference
http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...
- Unit testing Cmockery 简单使用
/********************************************************************** * Unit testing Cmockery 简单使用 ...
- Unit Testing a zend-mvc application
Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...
- Unit Testing PowerShell Code with Pester
Summary: Guest blogger, Dave Wyatt, discusses using Pester to analyze small pieces of Windows PowerS ...
- MVC Unit Testing学习笔记
MVC Unit Testing 参考文档: 1.http://www.asp.net/mvc/overview/testing 2.http://www.asp.net/mvc/tutorials/ ...
- 读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit
读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit Author: Andrew Hunt ,David Thomas with Matt ...
随机推荐
- Could not find action or result: There is no Action mapped for namespace [/] and action name [GetG
Could not find action or result: /car/GetGpsDataAction There is no Action mapped for namespace [/] ...
- JMeter--聚合报告之 90% Line 正确理解
90% Line 参数正确的含义: 虽然,我的上面理解有一定的道理,显然它(90% 用户的响应时间)是错误的.那看看JMeter 官网是怎么说的? 90% Line - 90% of the samp ...
- StackExchange.Redis 官方文档(六) PipelinesMultiplexers
原文:StackExchange.Redis 官方文档(六) PipelinesMultiplexers 流水线和复用 糟糕的时间浪费.现代的计算机以惊人的速度产生大量的数据,而且高速网络通道(通常在 ...
- GO语言学习(一)Windows 平台下 Go 语言的安装和环境变量设置
1. Go 语言 SDK 安装包下载和安装 GO语言安装包下载地址:https://www.golangtc.com/download 下载 go1.9.2.windows-amd64 2. Go 语 ...
- UML学习总结(1)——UML学习入门
随着亲手接触的项目越来越多,项目的复杂度越来越大,项目的理解程度也变的很难,尤其是在接收一个别人已经做好的项目时,你迫切先想到的就是"有没有文档啊",当然是各种文档,概要设计文档, ...
- VS2012载入DLL编译出现试图载入格式不对的程序; 以及执行出现Mixed mode assembly is built against version 'v2.0.50727' of the
VS2012载入DLL编译出现试图载入格式不对的程序:以及执行出现Mixed mode assembly is built against version 'v2.0.50727' of therun ...
- [PReact] Integrate Redux with Preact
Redux is one of the most popular state-management libraries and although not specific to React, it i ...
- POJ 1511 Invitation Cards (ZOJ 2008) 使用优先队列的dijkstra
传送门: http://poj.org/problem?id=1511 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1008 ...
- 线程堆栈大小 pthread_attr_setstacksize 的使用
pthread_create 创建线程时,若不指定分配堆栈大小,系统会分配默认值,查看默认值方法如下: # ulimit -s8192# 上述表示为8M:单位为KB. 也可以通过# ulimit -a ...
- [Angular] Using InjectionToken
Previously we have 'OpaqueToken', but it is DEPRECATED. The new one is called 'InjectionToken'. The ...