首先安装Unit Test Generator。
方法为:工具->扩展和更新->联机->搜索“图标为装有蓝色液体的小试管。vs2013c#测试using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;  namespace ConsoleApplication1_CXY {     class Program     {         statiUnit Test vs2013c#测试using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;  namespace ConsoleApplication1_CXY {     class Program     {         statiGenerator”,

编写代码,生成一个新的类,编写构造函数 与 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();
        }
    }
}
测试结果如图所示:

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

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


 
                    
            
                

相关文章:

  • 2021-12-23
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-06-18
  • 2021-10-21
  • 2022-12-23
相关资源
相似解决方案