zoukankan      html  css  js  c++  java
  • 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#测试。

    
    
  • 相关阅读:
    apicloud入门学习笔记1:简单介绍
    QT入门学习笔记1:为什么要选QT及QT软件下载
    Altium Designer入门学习笔记1.软件安装与资料收集
    win 下安装mysql 服务
    几秒后跳转到新页面
    计算3天的日期
    alibaba json
    WebService和Rest Service
    count(*),count(1)和count(主键)的区别
    mybatis替换符号
  • 原文地址:https://www.cnblogs.com/zhulingjie/p/5304054.html
Copyright © 2011-2022 走看看