Visual Studio Code Unit Testing

一、NUnitjavascript

project.jsonjava

{
  "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"
        }
      }
    }
  }
}

 

測試類json

using System;
using NUnit.Framework;

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

 

而後在集成終端裏面輸入dotnet test,就能夠運行Console Runnerapp

 

 

二、xunit測試

project.jsonui

{
  "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"
        }
      }
    }
  }
}

 

 測試類spa

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,就能夠運行測試debug

  

Visual Studio Code如今也能夠直接嗅探到測試方法,只須要在上面輕輕點擊run test或者debug test就能夠輕鬆的運行個別測試orm

相關文章
相關標籤/搜索