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
74
votes
11 answers

Unit Testing with functions that return random results

I don't think that this is specific to a language or framework, but I am using xUnit.net and C#. I have a function that returns a random date in a certain range. I pass in a date, and the returning date is always in range of 1 to 40 years before the…
Michael Stum
  • 177,530
  • 117
  • 400
  • 535
70
votes
7 answers

XUnit Assertion for checking equality of objects

I am using XUnit framework to test my C# code. Is there any assert method available in this framework which does the object comparison? My intention is to check for equality of each of the object's public and private member variables. I tried those…
inquisitive
  • 1,558
  • 4
  • 16
  • 22
68
votes
4 answers

How to run all tests in Visual Studio Code

The latest version of VS Code already provides an easy way of running a single test as pointed on Tyler Long's answer to the question Debugging xunit tests in .NET Core and Visual Studio Code. However, I am looking how can I run all tests contained…
Miguel Gamboa
  • 8,855
  • 7
  • 47
  • 94
67
votes
2 answers

Await Tasks in Test Setup Code in xUnit.net?

The exact situation is I'm doing E2E tests with Protractor.NET (.NET port of AngularJS's Protractor E2E framework) and I would like to make some web requests (and the API -- System.Net.Http.HttpClient -- has all Async/Task methods) to Arrange my…
Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97
65
votes
9 answers

Why is the xUnit Runner not finding my tests

I have a xUnit.net Test as follows: static class MyTestClass { [Fact] static void MyTestMethod() { } } The xUnit plugin for VS 2012 says: No tests found to run. TestDriven.net runs it fine but mentions something about Ad hoc: 1…
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
62
votes
8 answers

Pass array of string to xunit test method

I want to pass an array of string to one of my XUnit test method, but when I just do the following it doesn't work (array + params mechanism) [Theory] [InlineData(new object[] { "2000-01-02", "2000-02-01" })] public void…
Serge Intern
  • 2,669
  • 3
  • 22
  • 39
61
votes
3 answers

Should GetEnvironmentVariable work in xUnit tests?

If I set environment variables for a .Net Core web project in Visual Studio 2017 using the project properties page, I can read the value of the variable using Environment.GetEnvironmentVariable; however, when I set the environment variable for my…
Eric
  • 2,120
  • 1
  • 17
  • 34
57
votes
9 answers

Skipping a whole test class in xUnit.net

Is it possible to skip all tests from a specific class like in NUnit [TestFixture] [Ignore("Reason")] public class TestClass { }
dwonisch
  • 5,595
  • 2
  • 30
  • 43
54
votes
5 answers

MemberData tests show up as one test instead of many

When you use [Theory] together with [InlineData] it will create a test for each item of inline data that is provided. However, if you use [MemberData] it will just show up as one test. Is there a way to make [MemberData] tests show up as multiple…
NPadrutt
  • 3,619
  • 5
  • 24
  • 60
53
votes
5 answers

How can I stop the Visual Studio Test Runner when a test hangs

When a test hangs in a loop, the small green progress bar in the test runner does not proceed, but there is no way to stop the test run. Or is there? VS 2013 Edit: This occured when using the XUnit TestRunner. The Cancel button simply did not show…
citykid
  • 9,916
  • 10
  • 55
  • 91
52
votes
5 answers

How to set the test case sequence in xUnit

I have written the xUnit test cases in C#. That test class contains so many methods. I need to run the whole test cases in a sequence. How can I set the test case sequence in xUnit?
Pankaj Saha
  • 869
  • 3
  • 17
  • 37
49
votes
2 answers

How can XUnit be configured to show just the method name in the Visual Studio 2015 Test Explorer?

When using xunit.runner.visualstudio version 2.0.1 in Visual Studio 2015, the names of the tests show up fully qualified. Is there a way for the tests to show only the method name? Consider the following test: - namespace MySolution.Tests { …
Wayne Birch
  • 645
  • 6
  • 18
48
votes
5 answers

Can you mark XUnit tests as Explicit?

I'm making the transition from NUnit to XUnit (in C#), and I was writing some "Integrated Tests" (ITs) that I don't necessarily want the test runner to run as part of my automated build process. I typically do this for manually testing, when the…
neumann1990
  • 1,205
  • 1
  • 11
  • 18
44
votes
1 answer

ExpectedException xunit .net core

I'm writing unit test for core application. Im trying to check, that my class throws exception. But ExpectedException attribute throws compile exception: Error CS0246 The type or namespace name 'ExpectedException' could not be found (are you…
Timur Lemeshko
  • 2,747
  • 5
  • 27
  • 39
42
votes
6 answers

Is there an easy way in xunit.net to compare two collections without regarding the items' order?

In one of my tests, I want to ensure that a collection has certain items. Therefore, I want to compare this collection with the items of an expected collection not regarding the order of the items. Currently, my test code looks somewhat like…
feO2x
  • 5,358
  • 2
  • 37
  • 46
1
2
3
66 67