Questions tagged [xunit2]

Related to the version 2 of XUnit

Related to the version 2 of XUnit: https://github.com/xunit/xunit/releases

64 questions
4
votes
1 answer

Can I customise a Fixture in an XUnit constructor for use with Theory and AutoData?

Here is what I am trying to do: public class MyTests { private IFixture _fixture; public MyTests() { _fixture = new Fixture(); _fixture.Customize(x => x.With(y => y.UserId, 1)); } [Theory, AutoData] …
Holf
  • 5,605
  • 3
  • 42
  • 63
4
votes
1 answer

How do I access the IApplicationEnvironment from a unit test?

How can I access the IApplicationEnvironment from an xUnit 2 unit test? There are several scenarios where I think I need this, including: Read from a non-embedded configuration file built with the unit tests Create and write files relating to the…
Matt DeKrey
  • 11,582
  • 5
  • 54
  • 69
4
votes
2 answers

How to capture log4net output in xunit2

I've read http://xunit.github.io/docs/capturing-output.html and it seems to apply to making my test output specific message during the test running but I would really like to be able to capture the log4net output that is already integrated into the…
Jeff Martin
  • 10,812
  • 7
  • 48
  • 74
3
votes
1 answer

XUnit Class Fixture (IClassFixture) is being executed twice

TextFixture and Test public class TestFixture : IDisposable { public TestFixture() { var options = new ChromeOptions(); options.AddExcludedArgument("enable-automation"); …
Drago
  • 1,755
  • 3
  • 19
  • 30
3
votes
0 answers

Xunit Not Running Some Tests in Visual Studio 2019

Xunit2 is not running some tests properly from within Visual Studio 2019. I recently migrated from NUnit to Xunit2 (removing all references to it in my projects). I installed Xunit2 following the directions on the official page, along with the nuget…
3
votes
2 answers

AutoFixture, xUnit: Setup TypeRelays and inject service in constructor

I am trying to write some tests, I use xUnit.net, Moq, AutoFixture. I need to inject service to my test method: [Theory, AutoData] public void TestSmthCool(IService service) { } The IService has 3 dependencies which I want to mock. But, If I run…
user348173
  • 8,818
  • 18
  • 66
  • 102
3
votes
3 answers

Integration Testing with AutoMapper fails to initialise configuration

Frameworks & Packages .NETCoreApp 1.1 Xunit 2.2.0 AutoMapper 6.0.2 Microsoft.AspNetCore.TestHost 1.1.1 Microsoft.NET.Test.Sdk 15.0.0 Integration Test public class ControllerRequestsShould { private readonly TestServer _server; private…
3
votes
3 answers

XUnit Test Constructor dependence injection with Autofac

I am implementing Xunit with Autofac, I could make it work by below code: using (var scoped = DbFixture.Container.Resolve()) { var result = (scoped.GetAll()).ToList().Count(); Assert.Equal(2, result); } But I want to inject…
Edward
  • 28,296
  • 11
  • 76
  • 121
3
votes
1 answer

Stubed Unit of Work method with Moq doesn't return the expected integer

I have a project created using Asp.Net Core, but I have a problem with unit testing one part of my controller's action, I use xUnit.net(2.2.0-beta2-build3300) for testing and Moq(4.6.25-alpha) for mocking, and FluentAssertions(4.13.0) and…
Hamid Mosalla
  • 3,279
  • 2
  • 28
  • 51
3
votes
2 answers

XUnit2 not finding tests anymore after upgrading VS2015 to Update 3

When doing a clean / rebuild on my solution so the tests appear in the Test Explorer I get the following error: 'An Unexpected error detected. Check the Tests Output Pane for details.' And none of the tests appear anymore. When I check the tests…
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
3
votes
1 answer

Referencing standard dlls from a .NET Core XUnit project

I am using the latest version of XUnit and I followed these steps to get the Class Library (.NET Core) project started. All other libraries throughout my entire solution are only using 4.6.1 so I changed the frameworks section in project.json to the…
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
3
votes
1 answer

Getting "option" missing error with xUnit2 target in FAKE build file

When I add the example xUnit2 target to my FAKE build file, I'm getting this error: error FS0001: This expression was expected to have type string option but here has type string Target Example from FAKE xunit2…
ptilton
  • 142
  • 3
  • 13
2
votes
1 answer

xUnit test suite where inner class can access outer class' data

I have some large test suites so I broke them into inner/nested classes. That also makes the results in the VSCode test explorer more friendly. But it doesn't work well when there's common fixture data that's defined in the outer class: public class…
lonix
  • 14,255
  • 23
  • 85
  • 176
2
votes
1 answer

Not able to run version one xUnit.net tests using console runner in xUnit.net v2

In my project we are upgrading to xUnit 2. As a result, we upgraded the console runner also which is used to run tests on build server. We did not upgrade the exsting test projects to use xUnit 2. They are still referring to xUnit.1.9.2. As per the…
NotAgain
  • 1,927
  • 3
  • 26
  • 42
2
votes
2 answers

Comparing two List with the XUnit Assert function

The following is not asserting to true with XUnit (StartDate and EndDate are the only two public properties of DatePeriod): var actual = new List() { new DatePeriod() { StartDate = new DateTime(2017, 1, 20), EndDate = new…
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231