惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
Jina AI
Jina AI
N
Netflix TechBlog - Medium
GbyAI
GbyAI
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
I
Intezer
T
Tor Project blog
P
Palo Alto Networks Blog
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
Cloudbric
Cloudbric
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
Forbes - Security
Forbes - Security
Last Week in AI
Last Week in AI
S
Security Affairs
博客园 - Franky
F
Fortinet All Blogs
量子位
M
MIT News - Artificial intelligence
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
S
Secure Thoughts
V
Visual Studio Blog
AI
AI
美团技术团队
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
T
Threatpost
Cyberwarzone
Cyberwarzone

博客园 - 金鱼

2009年阅读的图书 SQL分页语句 const和readonly区别 jQuery使用说明 (转)Web页面中常用到的广告效果 接口和抽象类 在ASP.NET中重写URL 静态与非静态的区别 .net开发人员应该必备的十种工具(新/旧对比) (转)几种流行的JS框架的选择 ActionScript3系列课程(二)----流程控制和函数 ActionScript3系列课程(一)----基本元素 网联网之电子商务概念 设计模式之抽象工厂(一) 技术解析:什么是模式? 什么是框架?[转] 三层架构图[转] JS调用后台带参数的方法 弹出对话框并发生页面跳转 面试中常问的.NET算法问题
vs2005 单元测试
金鱼 · 2008-03-16 · via 博客园 - 金鱼

  由于VS2005中的单元测试比较简单,下面我直接通过一个简单的DEMO来说明它的使用方法。
一.新建一个类库项目[UnitTesting],在默认的class1中,写入一个简单的加法函数。

 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4
 5namespace UnitTesting
 6{
 7    public class Class1
 8    {
 9        public int Add(int i, int j)
10        {
11            return i + j;
12        }

13    }

14}

15

二.建立测试项。
可以直接测试方法(Add())点击右键,选择弹出的listmenu中选择第二项[创建单元测试相],默认的测试方法已经勾选,此时只需单击"确定"按钮即可;或者在menu中选择test中的新建测试,在弹出添加新建测试窗体中单元测试项目即可。我们可以看一下自动生成的Class1Test类中的原代码,下面我只是把与测试相关的代码贴出来了。

 1 /// <summary>
 2        ///Add (int, int) 的测试
 3        ///</summary>

 4        [TestMethod()]
 5        public void AddTest1()
 6        {
 7            Class1 target = new Class1();
 8
 9            int i = 0// TODO: 初始化为适当的值
10
11            int j = 0// TODO: 初始化为适当的值
12
13            int expected = 0;
14            int actual;
15
16            actual = target.Add(i, j);
17
18            Assert.AreEqual(expected, actual, "UnitTesting.Class1.Add 未返回所需的值。");
19            Assert.Inconclusive("验证此测试方法的正确性。");
20        }

三。我们在菜单的测试栏中选择窗口的测试管理器,然后选择我们需要测试的方法,再我们勾选方法的那一栏中点击右键“运行选中的测试”这一项,即可。但是显示的结果是没有结论,我们需要把Assert,Inconclusive("");给注释一下,就OK了。
还可以在测试方法中修改参数值和期望值等数据。按照以上的操作就可以实现VS2005中的单元测试了。
最后,我在把单元测试中常用的属性简单的罗列一下。

属性 描述

TestClass()

该属性表示一个测试装置。

TestMethod()

该属性表示一个测试用例。

AssemblyInitialize()

在执行为执行选择的第一个 TestClass() 中的第一个 TestMethod() 之前,执行带有该属性的方法。

ClassInitialize()

带有该属性的方法在执行第一个测试之前调用。

TestInitialize()

带有该属性的方法在执行每个 TestMethod() 之前调用。

TestCleanup()

带有该属性的方法在执行每个 TestMethod() 之后调用。

ClassCleanup()

带有该属性的方法在执行 ALL 测试之后调用。

AssemblyCleanup()

在执行为执行选择的第一个 TestClass() 中的第一个 TestMethod() 之后,执行带有该属性的方法。

Description()

提供关于给定 TestMethod() 的描述。

Ignore()

由于某种原因忽略 TestMethod()TestClass()

ExpectedException()

当测试特定异常时,如果使用该属性指定的异常不是从实现代码引发,则测试不会失败。