Reputation: 25158
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#?
Upvotes: 0
Views: 450
Reputation: 61885
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.
Upvotes: 0
Reputation: 14393
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:
Upvotes: 4