vs2013c#测试using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1_CXY { class Program { stati

首先安装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#测试。

				
时间: 2024-08-04 11:03:52

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

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

演示System.Collections.Generic的各容器类的用法. 包括:Dictionary,KeyValuePair,SortedDic tionary,SortedList,HashSet,SortedSet,List,Queue,Stack等 1 System.Collections.Generic.Dictionary<>; //键/值对集合 2 System.Collections.Generic.KeyValuePair<>; //键/值对结构, 作为 Dic

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

转载自:http://www.cnblogs.com/chenhuzi/p/4178194.html 今天有位同事在方法里加了一个IList<entity> 的返回值,也没有测试,直接发布,导致了如下错误. NotSupportedException: 无法序列化接口 System.Collections.Generic.IList InvalidOperationException: 反射“entity”时出错. InvalidOperationException: 无法反射方法 metho

[corefx注释说]-System.Collections.Generic.Queue&lt;T&gt;

为了节省时间,只写一些关注的方法好了,剩下的可以MSDN嘛XD 首先是声明部分,表示为队列是一个可用于枚举的只读集合 [DebuggerTypeProxy(typeof(QueueDebugView<>))] [DebuggerDisplay("Count = {Count}")] public class Queue<T> : IEnumerable<T>, System.Collections.ICollection, IReadOnlyColl

使用泛型 类型System.Collections.Generic.KeyValuePair需要2个类型参数

c#在准备使用System.Collections.Generic.KeyValuePair遍历的Hashtable时候,代码却提示有错误: 这其实是个非常简单的错误,Eclipse中通过工具弹出的提示解决方法,点下鼠标就能解决问题的,Visual Studio 2010却不行. 不过提示也说的比较清楚了,需要指定两个参数的类型. 根据你的Hashtable中保存的Key和Value的数据类型指定就可以了. 例如: KeyValuePair<string, int> KeyValuePair&

System.Collections.Generic.List&lt;T&gt; 与 System.Collections.ArrayList

[推荐] System.Collections.Generic.List<T> [原因] 泛型集合类List<T>在操作值类型的集合时可以不进行 装箱/拆箱 处理. 使得性能较 ArrayList提高了相当大的程度.因为托管堆中需要创建的对象次数减少了,所以需要应用程序执行的垃圾回收次数也相应减少.除此之外,开发人员还获得了编译时的类型安全性,源代码也因为强制类型转换的次数减少而变得更清晰.

C#学习之System.Collections.Generic 与 System.Collections 记录

1.了解C#集合 System.Collections 命名空间 System.Collections 命名空间包含接口和类,这些接口和类定义各种对象(如列表.队列.位数组.哈希表和字典)的集合. 类   类 说明 ArrayList 使用大小可按需动态增加的数组实现 IList 接口. BitArray 管理位值的压缩数组,该值表示为布尔值,其中 true 表示位是打开的 (1),false 表示位是关闭的 (0). CaseInsensitiveComparer 比较两个对象是否相等,比较时

Resx 文件无效。未能加载 .RESX 文件中使用的类型 System.Collections.Generic.List`1请确保已在项目中添加了必需的引用。

在C#程序编写过程中,会遇到:Resx 文件无效.未能加载 .RESX 文件中使用的类型 System.Collections.Generic.List1`请确保已在项目中添加了必需的引用. 主要原因很可能是使用了类的可序列化的原因,代码如下: [Serializable] public class TimeLineItem { public string Title; public string Content; public TimeLineItem(string content) { th

.Net多线程编程—System.Threading.Tasks.Parallel

System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel.Invoke 尽可能并行执行所提供的每个操作,除非用户取消了操作. 方法: 1)public static void Invoke(params Action[] actions); 2)public static void Invoke(ParallelOptions parallelOption

System.Threading.Tasks.Task引起的IIS应用程序池崩溃

问题现象 IIS应用程序池崩溃(Crash)的特征如下: 1. 从客户端看,浏览器一直处于连接状态,Web服务器无响应. 2. 从服务器端看(Windows Server 2008 + IIS 7.0),在事件日志中会出现Event ID为5010的错误: A process serving application pool 'q.cnblogs.com' failed to respond to a ping. The process id was '20080'. 这个错误的意思是:IIS检