首页 > 移动平台 > 详细

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

时间:2016-03-21 22:52:26      阅读:612      评论:0      收藏:0      [点我收藏+]

首先安装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

原文:http://www.cnblogs.com/zhulingjie/p/5304054.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!