zoukankan      html  css  js  c++  java
  • 使用Xunit进行单元测试

    http://xunit.github.io/docs/getting-started-desktop.html

    1. 新建一个类库项目

    2. 通过NuGet引入xunit,Shouldly,xunit.runner.visualstudio三个程序包。

    3. 编写代码

    public class Class1
    {
        public int Add(int x, int y)
        {
            return x + y;
        }
    
        public string Reverse(string str)
        {
            return new string(str.Reverse().ToArray());
        }
    }
    

      

    public class Class1Tests
    {
        [Fact]
        public void AddTest()
        {
            var class1 = new Class1();
            class1.Add(2, 2).ShouldBe(4);
        }
    
        [Fact]
        public void ReverseTest()
        {
            var class1 = new Class1();
            class1.Reverse("hello").ShouldBe("olleh");
        }
        [Fact]
        public void ReverseWithNull_Test()
        {
            var class1 = new Class1();
            class1.Reverse(null).ShouldBe(null);
        }
    }
    

      

    4. 在测试方法上右键执行

    —————————————————————— 

    ps:测试管理资源器打开方式

    附: VS插件

    ——————

    .Net Core项目中使用 Xunit进行单元测试  

     .NET Core系列 :4 测试

    {
      "version": "1.0.0-*",
      "testRunner": "xunit",
      "dependencies": {
    
        "xunit":"2.2.0-beta4-build3444",
        "Shouldly": "2.8.2",
        "xunit.runner.visualstudio": "2.2.0-beta4-build1194",
        "dotnet-test-xunit":   "2.2.0-preview2-build1029"
      },
    
      "frameworks": {
        "net452":{}
      }
    }
    

    版本兼容

    {
      "version": "1.0.0-*",
      "testRunner": "xunit",
    
      "dependencies": {
        "NSubstitute": "2.0.3",
        "Shouldly": "2.8.3",
        "xunit": "2.2.0",
        "xunit.runner.visualstudio": "2.2.0"
      },
      "runtimes": {
        "win10-x64": {}
      },
      "frameworks": {
        "net46": {
          "dependencies": {
            "dotnet-test-xunit": "2.2.0-preview2-build1029"
          }
        },
        "netcoreapp1.0": {
          "dependencies": {
            "Microsoft.NET.Test.Sdk": "15.0.0"
          }
        }
      }
    }
    

      

  • 相关阅读:
    linux性能监控三张图
    golang 之 defer(统计函数执行时间)
    golang之匿名函数
    php opcodes运行原理
    Mysql索引的类型
    字符串反转方法收集
    curl模拟请求常用参数
    windows10 使用gitblit搭建git服务器
    PHP程序员解决问题的能力
    mysql中union 查询
  • 原文地址:https://www.cnblogs.com/wj033/p/6108239.html
Copyright © 2011-2022 走看看