xunit

.Net Core 2.0 and xUnit doesn't run

蹲街弑〆低调 提交于 2019-12-05 19:17:43
VS2017 + Core 2.0. Created a brand new XUnit test project from template .csproj file: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> <PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit.runner.console" Version="2.3.1" /> </ItemGroup> </Project> Test: public class Class1 { [Fact] public void Test1() { Assert.Equal(1,

Is it possible to use Dependency Injection with xUnit?

ぐ巨炮叔叔 提交于 2019-12-05 09:48:21
问题 I have a test class with a constructor that needs an IService. public class ConsumerTests { private readonly IService _service; public ConsumerTests(IService servie) { _service = service; } [Fact] public void Should_() { //use _service } } I want to plugin my DI container of choice to build the test class . Is this possible with xUnit ? 回答1: Yes there is now, these two questions and answers should be consolidated in my opinion, see answer here Net Core: Execute All Dependency Injection in

Xunit multiple IClassFixtures

白昼怎懂夜的黑 提交于 2019-12-05 08:53:21
My question is How to setup multiple fixtures in one test class? But the constructor of Zoo class can not handle multiple fixtures. For exemple: public class Zoo : IClassFixture<Tiger>, IClassFixture<Wolf>, IClassFixure<Bird> { private IFixture fixture; public Zoo(IFixture fixture) { this.fixture = fixture; } [Fact] public void TestAnimal() { //Arrange int actualBonesCount = this.fixture.BonesCount; int expectedBonesCount = 2; //Act & Assert Assert.Equal(expectedBonesCount, actualBonesCount ); } } A tiger class public class Tiger : FixtureBase { public Tiger() { this.BonesCount = 4; } } A bird

How to get passed and fail test case count in xunit using cake(c# make) script

霸气de小男生 提交于 2019-12-05 08:14:56
I try to use the cake script for running the test cases written in Xunit using the cake script , I need to know the number of passed and failed test cases count. #tool "nuget:?package=xunit.runner.console" var testAssemblies = GetFiles("./src/**/bin/Release/*.Tests.dll"); XUnit2(testAssemblies); Reference : http://www.cakebuild.net/dsl/xunit-v2 Can anyone please suggest how to get the number of passed and failed test cases ? You'll have to use XUnit2Aliases​.XUnit2(IEnumerable < FilePath >, ​XUnit2Settings) + XmlPeekAliases for reading the XUnit output. var testAssemblies = GetFiles("./src/**

Separate In Memory Databases EF7

ぐ巨炮叔叔 提交于 2019-12-05 07:15:40
Is there any way to create a separate (isolated) instance of an EF7 In Memory Database? I am using the In Memory Database in Entity Framework 7 in my unit tests written in xUnit. I would like to be able to run the tests in parallel but this isn't really possible since it seems like the same in memory database is used for all the tests. What I would like is for each test to have its on isolated in memory database that isn't shared with the other tests that run in parallel. In EF Core you can pass a db name for InMemory db context. Something like var builder = new DbContextOptionsBuilder();

Running xunit.net tests in VSTS

孤人 提交于 2019-12-05 03:34:34
I have an issue running xunit.net tests in VSTS . When running the Build plan, the Test assemblies step produces the following log: 2017-03-21T12:11:39.3302859Z ##[section]Starting: Test Assemblies 2017-03-21T12:11:39.3382932Z ============================================================================== 2017-03-21T12:11:39.3382932Z Task : Visual Studio Test 2017-03-21T12:11:39.3382932Z Description : Run tests with Visual Studio test runner 2017-03-21T12:11:39.3382932Z Version : 1.0.84 2017-03-21T12:11:39.3382932Z Author : Microsoft Corporation 2017-03-21T12:11:39.3382932Z Help : More

How to capture output with XUnit 2.0 and FSharp style tests

China☆狼群 提交于 2019-12-05 01:43:12
Normally I write my unit tests in F# as open Swensen.Unquote open Xunit module MyTests = [<Fact>] let ``SomeFunction should return 10`` () = let a = SomeFunction() test <@ a = 10 @> [<Fact>] let ``SomeOtherFunction should return 11`` () = let a = SomeFunction() test <@ a = 11 @> If I wish to log to the console from xunit ( according to http://xunit.github.io/docs/capturing-output.html ) one needs to write a constructor that takes an ITestOutputHelper and then use that instead of Console.WriteLine and family. using Xunit; using Xunit.Abstractions; public class MyTestClass { private readonly

Is it possible to use Dependency Injection with xUnit?

陌路散爱 提交于 2019-12-04 23:59:04
I have a test class with a constructor that needs an IService. public class ConsumerTests { private readonly IService _service; public ConsumerTests(IService servie) { _service = service; } [Fact] public void Should_() { //use _service } } I want to plugin my DI container of choice to build the test class . Is this possible with xUnit ? Yes there is now, these two questions and answers should be consolidated in my opinion, see answer here Net Core: Execute All Dependency Injection in Xunit Test for AppService, Repository, etc Use Custom Web Application Factory and ServiceProvider

Mock HostingEnvironment.QueueBackgroundWorkItem in xunit test

我的梦境 提交于 2019-12-04 23:15:52
I have a method using HostingEnvironment.QueueBackgroundWorkItem which I wish to unit test some behaviour before this call, however, the test is failing with System.InvalidOperationException : Operation is not valid due to the current state of the object. I suspect this I need to mock the HostingEnvironment but unaware of how to. To resolve this issue I defined an interface public interface ITaskScheduler { void QueueBackgroundWorkItem(Action<CancellationToken> workItem); } In production code I inject implementation public class AspNetTaskScheduler : ITaskScheduler { public void

Xunit Unit Tests will not run

爷,独闯天下 提交于 2019-12-04 22:37:17
I am completely stuck on this issue. So my team has a unit test project in a services test project. The tests are discovered in the test explorer pane however when I try and run the tests I get these errors: 'Multiple test adapters with the same uri 'executor://xunit/VsTestRunner2' were found. Ignoring adapter 'Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner'. Please uninstall the conflicting adapter(s) to avoid this warning' '[xUnit.net 00:00:00.0251250] Skipping: (could not find dependent assembly 'Microsoft.Extensions.DependencyModel, Version=1.1.0')' 'No test is available in C:\. Make