首先安装Unit Test Generator。
方法为:工具->扩展和更新->联机->搜索“图标为装有蓝色液体的小试管。Unit Test Generator”,

编写代码,生成一个新的类,编写构造函数 与 add()函数。代码如下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication1_CXY
{
class Program
{
static void Main(string[] args)
{
}
}
public class test
{
public test(){ }
public int add(int a,int b)
{
return a + b;
}
}
}

在addTest()函数里编写测试代码,代码如下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication1_CXY;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ConsoleApplication1_CXY.Tests
{
[TestClass()]
public class testTests
{
[TestMethod()]
public void addTest()
{
int a=2,b=5,expect=7;
test t = new test();
int real = t.add(a,b); Assert.AreEqual(real,expect);
//Assert.Fail();
}
}
}
测试结果如图所示:

如此就完成了一个简单的c#测试。

												

vs2013c#测试using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1_CXY { class Program { stati的更多相关文章

  1. 无法将类型“System.Collections.Generic.IEnumerable<EmailSystem.Model.TemplateInfo>”隐式转换为“System.Collections.Generic.List<EmailSystem.Model.TemplateInf

    List<Model.Template> templateList = templateBLL.RecommendTemplateByOrder(modelEbay); List<M ...

  2. C#:system.collections.generic(泛型)

    1. array是一个固定长度的,如果要动态的存储的话就不行了,虽然 System.Collections.ArrayList(),是一个动态的存储的容器,但是没有对存储中的数据进行一个约束,所以非泛 ...

  3. HttpClient exception:ExceptionType:System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: Operation ca

    error msg: System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System. ...

  4. 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1

    在WPF中DataGrid 选择事件中获取SelectedItems 报错如下 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转 ...

  5. webservice asmx 无法序列化接口 System.Collections.Generic.IList

    转载自:http://www.cnblogs.com/chenhuzi/p/4178194.html 今天有位同事在方法里加了一个IList<entity> 的返回值,也没有测试,直接发布 ...

  6. Web Service接口返回泛型的问题(System.InvalidCastException: 无法将类型为“System.Collections.Generic.List`1[System.String]”的对象强制转换为类型“System.String[]”)

    在使用C#写Web Service时遇到了个很奇怪的问题.返回值的类型是泛型(我用的是类似List<string>)的接口,测试时发现总是报什么无法转换为对象的错误,百思不得其解. 后来在 ...

  7. 无法将类型“System.Collections.Generic.List<anonymous type:string ClassID,string ClsssName>”隐式转换为“System.Collections.Generic.List<Ecology.Model.EnergyFlowGraph>”

    无法将类型“System.Collections.Generic.List<anonymous type:string ClassID,string ClsssName>”隐式转换为“Sy ...

  8. System.Collections.Generic的各容器类的用法

    演示System.Collections.Generic的各容器类的用法. 包括:Dictionary,KeyValuePair,SortedDic tionary,SortedList,HashSe ...

  9. NHibernate无法将类型“System.Collections.Generic.IList<T>”隐式转换为“System.Collections.Generic.IList<IT>

    API有一个需要实现的抽象方法: public IList<IPermission> GetPermissions(); 需要注意的是IList<IPermission>这个泛 ...

随机推荐

  1. java使用纯命令行打包项目

    1: javac -d 编译之后的class文件输出目录   指定源文件位置即可.例如 对于多个包下面的源码编译,貌似javac不支持迭代编译,可能需要一次传入多个源码位置进行编译.一种便捷方法就是使 ...

  2. MP实战系列(十八)之XML文件热加载

    你还在为每次修改XML文件中的SQL重新启动服务器或者是等待几分钟而烦恼吗? 配置了热加载即可解决你的这个问题. 这就是XML文件热加载的目的,减少等待时间成本,提高开发效率. SSM框架配置(Spr ...

  3. Dawn开源项目

    今天本人给大家推荐一个阿里开源的前端构建和工程化工具Dawn. 一. Dawn是什么? Dawn 取「黎明.破晓」之意,原为「阿里云·业务运营团队」内部的前端构建和工程化工具,现已完全开源.它通过 p ...

  4. PAT B1025 反转链表 (25 分)

    给定一个常数 K 以及一个单链表 L,请编写程序将 L 中每 K 个结点反转.例如:给定 L 为 1→2→3→4→5→6,K 为 3,则输出应该为 3→2→1→6→5→4:如果 K 为 4,则输出应该 ...

  5. zookeeper&acticemq&redis&tomcat安装

    zookeeper安装  配置hosts  下载 wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar. ...

  6. windows安装wget

    windows安装wget1. 下载wget-1.11.4-1-setup.exehttps://jaist.dl.sourceforge.net/project/gnuwin32/wget/1.11 ...

  7. POJ 1904 King's Quest(SCC的巧妙应用,思维题!!!,经典题)

    King's Quest Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 10305   Accepted: 3798 Ca ...

  8. 实现MD5的加密和解密

    加密代码 public static string Encrypt(string Text, string sKey) { DESCryptoServiceProvider des = new DES ...

  9. 20155308《信息安全系统设计基础 嵌入式C语言课堂考试补博客

    20155308<信息安全系统设计基础 嵌入式C语言课堂考试补博客 知识点 置位 ?bits = bits | (1 << 7) ; /* sets bit 7 */ bits |= ...

  10. 2017-2018-2 《网络对抗技术》 20155310 第二周 Exp1 PC平台逆向破解(5)M

    2017-2018-2 <网络对抗技术> 20155310 第二周 Exp1 PC平台逆向破解(5)M 一.实践目标 1.1实践介绍 本次实践的对象是一个名为pwn1的linux可执行文件 ...