Visual Studio Code Unit Testing

1、NUnit

project.json

{
  "version": "1.0.0-*",
  "testRunner": "nunit",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {
    "NUnit": "3.5.0",
    "dotnet-test-nunit": "3.4.0-beta-3"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "portable-net45+win8",
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      }
    }
  }
}

 

测试类

using System;
using NUnit.Framework;

namespace ClassLibrary
{
    [TestFixture]
    public class Class1
    {
        [Test]
        public void Method1()
        {
            Assert.AreEqual(1101, 1100 + 1);
        }
    }
}

 

然后在集成终端里面输入dotnet test,就可以运行Console Runner

 

 

2、xunit

project.json

{
  "version": "1.0.0-*",
  "testRunner": "xunit",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {
    "xunit": "2.2.0-beta2-build3300",
    "dotnet-test-xunit": "2.2.0-preview2-build1029"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      }
    }
  }
}

 

 测试类

using System;
using Xunit;

namespace ClassLibrary
{
    public class Class1
    {
        public void Method1()
        {

        }

        [Fact]
        public void PassingTest()
        {
            int a = 5;
            int b = a;
            Assert.Equal(b, Add(2, 2));
        }

        [Fact]
        public void FailingTest()
        {
            Assert.Equal(5, Add(2, 2));
        }

        int Add(int x, int y)
        {
            return x + y;
        }
    }
}

 

和NUnit一样,输入dotnet test,就可以运行测试

  

Visual Studio Code现在也可以直接嗅探到测试方法,只需要在上面轻轻点击run test或者debug test就可以轻松的运行个别测试

 

转载于:https://www.cnblogs.com/Richeir/p/6397979.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作者:Nick Randolph, David Gardner 出版日期:July 28, 2008 出版社:Wrox Press 页数:1032 ISBN:ISBN-10: 0470229888 ISBN-13: 978-0470229880 文件格式:PDF 书籍简介 Product Description Professional Visual Studio 2008Microsoft Visual Studio 2008 is the latest version in the ongoing evolution of the Integrated Development Environment (IDE), and this resource examines the diverse facets of the IDE—from common tasks to intricate functions to the powerful tools that accompany the main code editing and design windows. Written by a unique author duo and offering an in-depth look at the powerful and fascinating features and techniques of the IDE, this book explores each aspect of the development life cycle from the perspective of how Visual Studio 2008 can make your life easier. Each chapter is packed with examples that illustrate uses for various tools, commands, and shortcuts of Visual Studio 2008. You will gradually learn to identify where a feature is used, conclude how you can use it to its fullest potential, and then seamlessly apply that feature to help solve real-world problems. What you will learn from this book How to create project templates and wizards Methods for using IntelliSense, code refactoring, class modeling, and unit testing Tips for using DataSets, LINQ, and Synchronization Services for working with data How to build web applications using ASP.NET AJAX, Silverlight, and ASP.NET MVC Ideas for building Office and Mobile applications, WPF, WCF, and WF projects Ways to effectively analyze and identify bugs using the advanced debugging features How to automate repetitive tasks using the Visual Studio 2008 add-ins and macros Suggestions for using Visual Studio Team System components coupled with Team Foundation Server Techniques for building more secure applications Who this book is for This book is for programmers who want to become proficient with the latest version of Visual Studio and are interested in the advanced capabilities of the IDE. Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job. From the Back Cover Professional Visual Studio 2008 Microsoft Visual Studio 2008 is the latest version in the ongoing evolution of the Integrated Development Environment (IDE), and this resource examines the diverse facets of the IDE—from common tasks to intricate functions to the powerful tools that accompany the main code editing and design windows. Written by a unique author duo and offering an in-depth look at the powerful and fascinating features and techniques of the IDE, this book explores each aspect of the development life cycle from the perspective of how Visual Studio 2008 can make your life easier. Each chapter is packed with examples that illustrate uses for various tools, commands, and shortcuts of Visual Studio 2008. You will gradually learn to identify where a feature is used, conclude how you can use it to its fullest potential, and then seamlessly apply that feature to help solve real-world problems. What you will learn from this book How to create project templates and wizards Methods for using IntelliSense, code refactoring, class modeling, and unit testing Tips for using DataSets, LINQ, and Synchronization Services for working with data How to build web applications using ASP.NET AJAX, Silverlight, and ASP.NET MVC Ideas for building Office and Mobile applications, WPF, WCF, and WF projects Ways to effectively analyze and identify bugs using the advanced debugging features How to automate repetitive tasks using the Visual Studio 2008 add-ins and macros Suggestions for using Visual Studio Team System components coupled with Team Foundation Server Techniques for building more secure applications Who this book is for This book is for programmers who want to become proficient with the latest version of Visual Studio and are interested in the advanced capabilities of the IDE. Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值