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 ...
随机推荐
- 推荐一个iOS应用UI界面设计站点
Patterns是一个分享ios应用UI界面的站点,专注于分享iOS应用UI界面的细节.依照设计元素进行分类,依照iOS经常使用功能对各类UI进行分类展示. 链接:url=http%3A%2F%2Fw ...
- python 的spyder用法
ctrl+tab可以进行跳转 https://blog.csdn.net/luckygirl0809/article/details/79929491
- (转)kvm虚拟机中,如何给子系统更换光盘
转自:http://www.cnblogs.com/york-hust/archive/2012/06/12/2546334.html 启动kvm后,在kvm窗口中,按下CTRL+ALT+2,切换至q ...
- python3 turtle 画国际象棋棋盘
python3 turtle 画国际象棋棋盘 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import turt ...
- [求助]linux同一目录可否挂载多个数据盘?
https://bbs.aliyun.com/read/281222.html?pos=20
- GDB中创建要素数据集
转自 在geodatabase中创建要素集 //在数据集中创建要素 private void menuItem25_Click(object sender, System.EventArgs e) { ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Geodatabase模型
原文 Geodatabase模型 地理数据模型是地理实体及其关系的形式化抽象和数学描述.随着数据库.面向对象等技术的发展,面向对象的地理数据模型成为大型空间数据库的首选方案,它克服了传统地理数据模型的 ...
- 各个RFC
RFC:Request For Comments(RFC),是一系列以编号排定的文件.文件收集了有关互联网相关信息,以及UNIX和互联网社区的软件文件.目前RFC文件是由Internet Societ ...
- php BC高准确度函数库
<? php *************************************************************************************** *p ...