0

I downloaded opensource project asp.net-webstack to just bacause of curiosity to check the source code. I have found unittest in C# like this:

// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

using System.Net.Http;
using Microsoft.TestCommon;

namespace System.Web.Http.Routing
{
    public class HttpRouteTest
    {
        [Theory]
        [InlineData("123 456")]
        [InlineData("123 {456")]
        [InlineData("123 [45]6")]
        [InlineData("123 (4)56")]
        [InlineData("abc+56")]
        [InlineData("abc.56")]
        [InlineData("abc*56")]
        [InlineData(@"hello12.1[)]*^$=!@23}")]
        public void GetRouteData_HandlesUrlEncoding(string id)
        {
            HttpRoute route = new HttpRoute("{controller}/{id}");
            Uri uri = new Uri("http://localhost/test/" + id + "/");
            IHttpRouteData routeData = route.GetRouteData("", new HttpRequestMessage(HttpMethod.Get, uri));
            Assert.Equal("test", routeData.Values["controller"]);
            Assert.Equal(id, routeData.Values["id"]);
        }
    }
}

How I run this test from Visual Studio? There is no TestMethod and TestClass attribute. The standard execution from context menu does not work.

Is it some smart way how to run unittest agains multiple data sets in C#?

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
  • 2
    It's just an xUnit test. I don't know which "standard execution" you're using, but if you've got an xUnit test runner, it should be fine. – Jon Skeet Jan 26 '16 at 21:01

2 Answers2

4

As far as I can tell InlineData is an xUnit testing attribute.

What makes this work in Visual Studio (2012 or higher) is that the xUnit test adapter (i.e. the NuGet package xunit.runner.visualstudio) is wired into the test project when the reference to the xUnit NuGet package is added.

Here is a link with some more details:

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
chief7
  • 14,263
  • 14
  • 47
  • 80
  • This is no longer the case, def for VS 2015 but I imagine also for earlier version - you're actually [instructed to *remove* that plugin in the troubleshooting section of the Desktop](https://xunit.github.io/docs/getting-started-desktop.html#run-tests-visualstudio) - http://xunit.github.io/docs/getting-started-dnx.html is a better link – Ruben Bartelink Feb 01 '16 at 08:43
  • That's referring to uninstalling the old VSIX installed version. You should use the Nuget package as my referenced post and your link as well instructs. – chief7 Feb 01 '16 at 12:08
  • Sorry, I just found your post as it was misleading - for 3 years+ one had to explicitly install a plugin and you appeared to be alluding to such a procedure (I do acknowledge that you didnt specifically state that). Feel free to roll back my edit if you think it makes matters worse :) – Ruben Bartelink Feb 01 '16 at 12:33
  • No, I think these comments help to clarify. Thanks for your input! – chief7 Feb 01 '16 at 13:44
0

In xUnit v2, xUnit's NuGet package includes reference to a NuGet (xunit.runner.visualstudio) that makes the tests discoverable by the VS runner in VS2012+. See the xUnit docs for an overview.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • [Slightly related answer](http://stackoverflow.com/a/35103782/11635) [by me] (although it pertains specifically to *Desktop* tests – Ruben Bartelink Feb 01 '16 at 08:39