Questions tagged [xunit.net]

xUnit.net is a unit testing tool for the .NET Framework. Written by the original inventor of NUnit, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages. It works with ReSharper, CodeRush, and TestDriven.NET.

Written by the original inventor of NUnit v2, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages. xUnit.net works with ReSharper, CodeRush, TestDriven.NET and Xamarin

See more at http://xunit.github.io/

1001 questions
42
votes
5 answers

How to refer to test files from Xunit tests in Visual Studio?

We’re using Xunit for testing. We’re running our tests via the built-in Visual Studio 2013 Test Runner, using the Xunit plugin. The issue is that some of the tests need to refer to files on the filesystem. It seems that Xunit (or the VS Test…
andrewf
  • 1,350
  • 1
  • 13
  • 19
41
votes
4 answers

Xunit 2.3.0 Unable to pass dates as inline params

In xUnit 2.2 and prior versions, we were able to pass date strings as inline data when implementing a Theory. [Theory] [InlineData("title 1", "testing 1", 1, "Educational", "2017-3-1", "2018-12-31")] [InlineData("title 2", "testing 2", 2, "Self…
Wijitha
  • 1,189
  • 2
  • 12
  • 22
40
votes
7 answers

xUnit doesn't write message to the output pane

In Visual Studio 2015 Community I have a sample ASP.NET 5 (vNext) project and a project with unit tests (xUnit.net). The version of DNX is 1.0.0-beta5. My goal is to add messages during the test run to the output pane. Here I took a way to do this,…
Farfi
  • 473
  • 1
  • 4
  • 8
38
votes
3 answers

dotnet test > is there a way to show list of tests ran in console?

When running dotnet test, is there a way of showing a list of all tests ran in console instead of some output file? Would be ideal to see a list like this in console: x test1 test2 test3 x test4 instead of just overall test statistics (ran,…
dee zg
  • 13,793
  • 10
  • 42
  • 82
36
votes
5 answers

Which is better? Unit-test project per solution or per project?

Is it better to have a unit-test project per solution or a unit-test project per project? With per solution, if you have 5 projects in the solution you end-up with 1 unit-test project containing tests for each of the 5 projects. With per project, if…
Nikos Baxevanis
  • 10,868
  • 2
  • 46
  • 80
34
votes
4 answers

Having an actual decimal value as parameter for an attribute (example xUnit.net's [InlineData]

I'm trying to do unit testing with xUnit.net. I want a 'Theory' test with '[InlineData]' which includes 'decimals': [Theory] [InlineData(37.60M)] public void MyDecimalTest(decimal number) { Assert.Equal(number, 37.60M); } This is not possible…
Tim Pohlmann
  • 4,140
  • 3
  • 32
  • 61
34
votes
3 answers

How to dynamically skip a test with Xunit 2.0?

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…
nulltoken
  • 64,429
  • 20
  • 138
  • 130
30
votes
3 answers

How to run setup code only once in an xUnit.net test

I'm trying to setup my tests using Xunit. I have a requirement to delete all images in a folder start of the tests, and then each method does some image resizing and saves a copy of it's output to the folder. The folder should only be emptied once,…
Chris
  • 7,996
  • 11
  • 66
  • 98
29
votes
2 answers

Are there any good documentations / books / tutorials for xUnit.NET?

On my search for a Unit-Testing tool for C# i have found xUnit.NET. Untill now, i read most of the articles on http://xunit.codeplex.com/ and even tried out the examples given at How do I use xUnit.net?. But sadly, on the offical page i could just…
DIF
  • 2,470
  • 6
  • 35
  • 49
28
votes
2 answers

Visual Studio 2017 Unit Test Project vs xUnit Test Project

In .NET Core under Visual Studio 2015 one had to create a unit test project that was based on xunit, though the command line (no dedicated project was available in Visual Studio for .NET Core). In Visual Studio 2017, under .NET Core section there…
developer82
  • 13,237
  • 21
  • 88
  • 153
28
votes
3 answers

How can I add an assembly binding redirect to a .net core unit test project?

I'm trying to create a .net core unit test project against framework 4.6.1 which tests an project dependent on Microsoft.SqlServer.Types (10.0.0.0). Prior to .net core I'd add an app.config file with the binding redirect. I've tried this but the…
JeffreyABecker
  • 2,724
  • 1
  • 25
  • 36
28
votes
2 answers

xUnit not awaiting async test

On VS 2013, I can't get this async test to fail. I have xUnit 1.8.0.1539 (installed from nuget), with the xUnit Test Runner VS extension (0.99.5). All current, AFAIK. I happen to also have Moq, AutoFixture, and FluentAssertions reference in the unit…
Alan McBee
  • 4,202
  • 3
  • 33
  • 38
28
votes
3 answers

Is there a more appropriate to test if the constructor throws an exception?

Normally you test, if an exception gets thrown in a certain method, as follows. I use FluentAssertions: [Fact] public void Exception_gets_thrown() { // Arrange var foo = new Foo("validArgument"); // Act/Assert foo.Invoking(f =>…
Michael Schnerring
  • 3,584
  • 4
  • 23
  • 53
26
votes
3 answers

How to setup Mock of IConfigurationRoot to return value

I have used IConfigurationRoute to access a directory like this. if (type == "error") directory = _config.GetValue("Directories:SomeDirectory"); _config is IConfigurationRoot injected in the constructor. I tried the following way to mock…
Shaurav Adhikari
  • 741
  • 3
  • 10
  • 22
24
votes
2 answers

ExecutionTimer.cs not found when stepping into code

I am writing some tests using XUnit framework and have to use some external code referenced through a dll. When I try to step into the method call, helper.GetEntity(), I get the following window and the execution exits. [Fact] public void…
Codehelp
  • 4,157
  • 9
  • 59
  • 96
1 2
3
66 67