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
412
votes
7 answers

NUnit vs. MbUnit vs. MSTest vs. xUnit.net

There are quite a lot of unittesting frameworks out there for .NET. I found this little feature comparison: http://xunit.github.io/docs/comparisons.html Now I am to choose the best one for us. But how? Does it matter? Which one is most future proof…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
233
votes
27 answers

Unable to find testhost.dll. Please publish your test project and retry

I have a simple dotnet core class library with a single XUnit test method: TestLib.csproj: netstandard2.0
Matt W
  • 11,753
  • 25
  • 118
  • 215
205
votes
11 answers

Execute unit tests serially (rather than in parallel)

I am attempting to unit test a WCF host management engine that I have written. The engine basically creates ServiceHost instances on the fly based on configuration. This allows us to dynamically reconfigure which services are available without…
jrista
  • 32,447
  • 15
  • 90
  • 130
167
votes
8 answers

What's the idiomatic way to verify collection size in xUnit?

I have in my test suite a test that goes something like this: [Fact] public void VerifySomeStuff() { var stuffCollection = GetSomeStuff(); Assert.Equal(1, stuffCollection.Count()); } This test works as I expect, but when I run it xUnit…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
162
votes
6 answers

xUnit.net: Global setup + teardown?

This question is about the unit testing framework xUnit.net. I need to run some code before any test is executed, and also some code after all tests are done. I thought there should be some kind of attribute or marker interface to indicate the…
Codism
  • 5,928
  • 6
  • 28
  • 29
152
votes
12 answers

Pass complex parameters to [Theory]

Xunit has a nice feature: you can create one test with a Theory attribute and put data in InlineData attributes, and xUnit will generate many tests, and test them all. I want to have something like this, but the parameters to my method are not…
zchpit
  • 3,071
  • 4
  • 28
  • 43
139
votes
6 answers

Test parameterization in xUnit.net similar to NUnit

Are there any means in xUnit.net framework similar to the following features of NUnit? [Test, TestCaseSource("CurrencySamples")] public void Format_Currency(decimal value, string expected){} static object[][] CurrencySamples = new object[][] { …
UserControl
  • 14,766
  • 20
  • 100
  • 187
136
votes
8 answers

Mocking IPrincipal in ASP.NET Core

I have an ASP.NET MVC Core application that I am writing unit tests for. One of the action methods uses User name for some functionality: SettingsViewModel svm = _context.MySettings(User.Identity.Name); which obviously fails in the unit test. I…
Felix
  • 9,248
  • 10
  • 57
  • 89
128
votes
11 answers

Run code once before and after ALL tests in xUnit.net

TL;DR - I'm looking for xUnit's equivalent of MSTest's AssemblyInitialize (aka the ONE feature it has that I like). Specifically I'm looking for it because I have some Selenium smoke tests which I would like to be able to run with no other…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
121
votes
2 answers

Difference between Fact and Theory? - xUnit.net

I'm new to xUnit.net and AutoFixture. I'm currently working on a "testproject" to get familiar with xUnit.net and Autofixture. There is one little thing I don't understand. What is the difference between [Fact] and [Theory, AutoMoqData]? Could you…
sternze
  • 1,524
  • 2
  • 9
  • 15
87
votes
2 answers

How do I run specific tests using dotnet test?

I have a large test suite in a .NET Core project. I can use the Test Explorer window to select a few tests to run. I can also run the whole test suite on the command line with dotnet test. Is there a way to run only one (or a few) tests on the…
Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
86
votes
2 answers

xunit Assert.ThrowsAsync() does not work properly?

So I have a test like the following: [Fact] public void Test1() { Assert.ThrowsAsync(() => MethodThatThrows()); } private async Task MethodThatThrows() { await Task.Delay(100); throw new…
Dmitry
  • 1,220
  • 2
  • 11
  • 18
81
votes
4 answers

Cannot find Assert.Fail and Assert.Pass or equivalent

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=…
naeron84
  • 2,955
  • 3
  • 30
  • 37
78
votes
8 answers

xUnit.net does not capture console output

I just started testing xUnit.net, but it doesn't seem to capture any output (Console, Debug, Trace), as I would have expected. Is that possible? I am using a sample .NET 4.0 class-library with xUnit.net 1.8.
kfuglsang
  • 2,385
  • 2
  • 21
  • 26
76
votes
14 answers

Is Assert.Fail() considered bad practice?

I use Assert.Fail a lot when doing TDD. I'm usually working on one test at a time but when I get ideas for things I want to implement later I quickly write an empty test where the name of the test method indicates what I want to implement as sort of…
Mendelt
  • 36,795
  • 6
  • 74
  • 97
1
2 3
66 67