xunit.net

How to associate a XUnit Fact to a Test Case in TFS

吃可爱长大的小学妹 提交于 2019-12-07 12:21:02
问题 I am trying to figure out how to associate a Test Case in TFS 2018 to a Xunit Fact in a .Net Core project. If i click on the XUnit Fact in the Visual Studio 2017 Test Explorer, the association option is disabled. Does anyone know how to associate a Xunit Fact to a Test Case in TFS? 回答1: There is a Rest API could update work item filed. For example: PATCH https://servername:8080/tfs/DefaultCollection/_apis/wit/workitems/[testcaseid]?api-version=1.0 Content-Type: application/json-patch+json

Visual studio with xUnit, Assert.Throws and “Exception was unhandled by user code”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 05:46:36
问题 i am trying to run tests inside a dll application (VS2010/C#) using using xUnit 1.8.0.1549. To do so i run xUnit via visual studio using "Start External Program" under "Start Action" in the project properties, running the dll via the GUI runner (C:\mypath\xunit.gui.clr4.x86.exe). I want to test if some methods raise exception, to do so, i use something like the following: Assert.Throws<Exception>( delegate { //my method to test... string tmp = p.TotalPayload; } ); The problem is that the

xunit add info to output

一曲冷凌霜 提交于 2019-12-06 22:33:56
问题 Does anyone know how to add additional info to the output console when running xUnit tests? I'm using testdriven.net, but I don't think that is where my answer lies. I am using a IUseFixture (actually IClassFixture from 2.0) to maintain data between tests. When a test fails I want to output some of that contextual data along with the failure and the stack trace that you usually get. Does anyone know of a hook I can use? 回答1: You can use ITestOutputHelper to write any output to the test result

Xunit not working using Visual Studio Team Services Build VNext

℡╲_俬逩灬. 提交于 2019-12-06 12:42:40
After following several blogs detailing how to get xUnit working with Team Services Build vNext: http://tech.trailmax.info/2014/01/run-xunit-in-hosted-team-foundation-service/ Running unit tests in TFS/VSO Build vNext using xUnit adapter http://www.donovanbrown.com/post/2015/06/15/how-to-run-xunit-test-with-vnext-build None of which worked for me. From examining the build logs I get the following warnings for each of my test assemblies. -------------------- Warning: [xUnit.net 00:00:00.1644156] Exception discovering tests from CHO.SAM.Business.Test: System.BadImageFormatException: Could not

Non-code-generated forwarding shim for testing private methods

烂漫一生 提交于 2019-12-06 11:50:20
问题 In general, I design classes in such a manner as to not require access to privates for testing purposes. An InternalsVisibleTo can also assist. However, I'm currently dealing with a codebase that has a few area which have become reliant on the [private accessors mechanism in VSTS](http://msdn.microsoft.com/en-us/library/ms184807(VS.80).aspx) (i.e., using VSCodeGenAccessors to generate *_Accessor classes which have forwarding that use reflection to invoke private members (and optionally

Unit test WebApi2 passing header values

萝らか妹 提交于 2019-12-06 10:53:38
问题 I am working on a project using WebApi2. With my test project I am using Moq and XUnit. So far testing an api has been pretty straight forward to do a GET like [Fact()] public void GetCustomer() { var id = 2; _customerMock.Setup(c => c.FindSingle(id)) .Returns(FakeCustomers() .Single(cust => cust.Id == id)); var result = new CustomersController(_customerMock.Object).Get(id); var negotiatedResult = result as OkContentActionResult<Customer>; Assert.NotNull(negotiatedResult); Assert.IsType

Instantiating IOptions<> in xunit

本秂侑毒 提交于 2019-12-06 02:17:41
问题 I'm trying to write an xunit test for a class (in a .net Core project) that looks something like: public Class FoodStore:IFoodStore { FoodList foodItems; public FoodStore(IOptions<FoodList> foodItems) { this.foodItems = foodItems; } public bool IsFoodItemPresentInList(string foodItemId) { //Logic to search from Food List } }` Note: FoodList is actually a json file, containing data, that is loaded and configured in the Startup class. How can I write an xunit test with appropriate dependency

Can't get XUnit tests working with Visual Studio 2017 RC

霸气de小男生 提交于 2019-12-06 01:18:57
问题 For the life of me I can't get unit testing working in Visual Studio 2017 from the new msbuild-based netcoreapp1.0 xunit project template. The requirement is for unit tests to work both inside Visual Studio (for the devs) and from dotnet test on the CLI for the automated build process however, I can't get either working consistently. Here is what I have tried: In an existing solution, create a new project and select .NET Core > xUnit Test Project . Build project from Visual Studio, default

Howto resolve .net test hangs on “Starting test execution, please wait…”

南楼画角 提交于 2019-12-06 01:10:54
问题 I am trying to execute dotnet test from the command line on our Jenkins build server, but it just hangs on: Starting test execution, please wait... It works fine when running this command locally If I switch to using dotnet xunit it fails with the following: 15:42:57 Locating binaries for framework netcoreapp2.1... 15:42:58 Running .NET Core 2.1 tests for framework netcoreapp2.1... 15:42:58 The specified framework version '2.1' could not be parsed 15:42:58 The specified framework 'Microsoft

How to associate a XUnit Fact to a Test Case in TFS

人盡茶涼 提交于 2019-12-05 22:43:08
I am trying to figure out how to associate a Test Case in TFS 2018 to a Xunit Fact in a .Net Core project. If i click on the XUnit Fact in the Visual Studio 2017 Test Explorer, the association option is disabled. Does anyone know how to associate a Xunit Fact to a Test Case in TFS? PatrickLu-MSFT There is a Rest API could update work item filed . For example: PATCH https://servername:8080/tfs/DefaultCollection/_apis/wit/workitems/[testcaseid]?api-version=1.0 Content-Type: application/json-patch+json Body: [ { "op": "add", "path": "/fields/Microsoft.VSTS.TCM.AutomatedTestName", "value": "