xunit.net

Collection fixture won't inject

浪子不回头ぞ 提交于 2019-12-04 16:05:25
问题 I'm using xUnit 2.0 collection fixtures to share a common database setup/teardown between a number of different test classes. The fixture also provides some helper properties, so I'm injecting it into each test class. I recreated the example in the docs, but when I run the test, it fails immediately with: The following constructor parameters did not have matching fixture data: IntegrationTestFixture fixture This seems to happen regardless of whether I'm using xUnit Facts or Theories, or which

Is there a way to unit test an async method?

亡梦爱人 提交于 2019-12-04 15:42:07
问题 I am using Xunit and NMock on .NET platform. I am testing a presentation model where a method is asynchronous. The method creates an async task and executes it so the method returns immediately and the state I need to check aren't ready yet. I can set a flag upon finish without modifying the SUT but that would mean I would have to keep checking the flag in a while loop for example, with perhaps timeout. What are my options? 回答1: Does your object feature any sort of signal that the

Cannot find Assert.Fail and Assert.Pass or equivalent

為{幸葍}努か 提交于 2019-12-04 14:55:33
问题 I used to use these in NUnit and they are really useful. Any idea how to do something like that? EDIT, CODE SAMPLE: bool condition = false;//would be nice not to have this observable.Subscribe(_ => { if (real test) condition= true;//Assert.Pass() }); StartObservable(); Assert.True(condition);//Assert.Fail() 回答1: The documentation includes a comparison chart including this: Fail - xUnit.net alternative: Assert.True(false, "message") (It doesn't show Assert.Pass , and I've never used that

Using XUnit with Visual Studio Online

心不动则不痛 提交于 2019-12-04 11:50:05
I've setup my build as below using the build definition. I'm using XUnit and locally my tests are discovered and run. I've tested the glob **\*spec*.dll and it finds all my test dlls and the build log shows that those dlls are in fact built. However in the build log I get Run VS Test Runner No test found. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again. Which seems to suggest it is trying to use the MSTest test runner instead of the XUnit test runner. How do I tell the build for visual studio online to use the XUnit

How to dynamically skip a test with Xunit 2.0?

China☆狼群 提交于 2019-12-04 09:53:36
问题 Xunit 1.9.x provides the user with the DynamicSkipExample.cs example to help him setting up dynamic skipping of a [Fact] . This has proven to be quite useful when performing some cross-platform development. This allows a test to be temporarily ignored when it cannot be properly run because of the underlying context (OS, filesystem, ...). However, this example has been dropped in commit 2deeff5 on the road to version 2.0. How can one re-implement such a functionality through one of the

Instantiating IOptions<> in xunit

[亡魂溺海] 提交于 2019-12-04 07:41:06
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 injection to test the IsFoodItemPresentInList method ? You could use OptionsWrapper<T> class to fake your

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

痞子三分冷 提交于 2019-12-04 06:01:34
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 test appears and runs successfully, now run dotnet test from powershell prompt, get: > dotnet test Test

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

我怕爱的太早我们不能终老 提交于 2019-12-04 05:24:21
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.NETCore.App', version '2.1' was not found. 15:42:58 - Check application dependencies and target a

AutoFixture in F# UnitTest Project Not Displaying Unit Tests in Test Explorer

删除回忆录丶 提交于 2019-12-04 03:51:41
问题 I have a Visual Studio 2012 Project and the following NuGet Packages installed: AutoFixture with Auto Mocking using Moq Autofixture with xUnit.net data theories AutoFixture Moq xUnit.net: Extensions xUnit.net: Runners xUnit.net Given the following contrived Logger class (Logger.fs): namespace FUnit type public ILoggerContext = abstract member LogPath :string type public LoggerContext (logPath :string) = member val LogPath = logPath with get, set interface ILoggerContext with member this

Visual Studio 2015 Test Explorer does not see XUnit dnx traits

别来无恙 提交于 2019-12-04 03:04:09
问题 The Visual Studio 2015 Test Explorer does not recognize my test traits. When I add this to a test in a DNX project: [Trait("Category", "Test")] the test still shows up in the Test Explorer under the No Traits group (when grouping tests by Traits). 回答1: Looks like this is already logged as an issue: VS 2015 Bugs - Traits and Project Grouping in Test Explorer #485 来源: https://stackoverflow.com/questions/32258618/visual-studio-2015-test-explorer-does-not-see-xunit-dnx-traits