Questions tagged [xunit]

xUnit is the collection name for unit-testing compliant frameworks following a specific architecture. Implementation differs from language to language but the framework should consist of a Test Runner, Test Case, Test Fixture (Context), Test Suite, Test Execution, Test Result Formatter and Assertions

xUnit has been implemented for most languages, examples include JUnit, NUnit, CUnit, CppUnit, xUnit.net and more. The first implementation was made for Smalltalk by Kent Beck and is called SUnit.

3147 questions
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
64
votes
7 answers

How to Unit Test with ActionResult?

I have a xUnit test like: [Fact] public async void GetLocationsCountAsync_WhenCalled_ReturnsLocationsCount() { _locationsService.Setup(s => s.GetLocationsCountAsync("123")).ReturnsAsync(10); var controller = new…
Richard Collette
  • 5,462
  • 4
  • 53
  • 79
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
4 answers

How to implement XUnit descriptive Assert message?

Context in XUnit github I found this: Add Assert.Equal(expected, actual, message) overload #350 (so a developer ask for a non existing overload see below) Quote from the answer: We are a believer in self-documenting code; that includes your…
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
59
votes
3 answers

xUnit Equivalent of MSTest's Assert.Inconclusive

What is the xUnit equivalent of the following MSTest code: Assert.Inconclusive("Reason"); This gives a yellow test result instead of the usual green or red. I want to assert that the test could not be run due to certain conditions and that the test…
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
59
votes
2 answers

xUnit or NUnit? What advantages and disadvantages of each other?

What are the pluses and minuses of each framework, comparing to each other? How well they work with ASP.NET MVC? How well they support mocking?
Dmitry
  • 789
  • 2
  • 6
  • 7
55
votes
5 answers

How to verify ILogger.Log extension method has been called using Moq?

I created a xUnit project to test this sample code public class ClassToTest { private readonly ILogger _logger; public ClassToTest(ILogger logger) { _logger = logger; } public void Foo() =>…
Question3r
  • 2,166
  • 19
  • 100
  • 200
54
votes
11 answers

how to debug with xUnit?

I'm learning xUnit and so far, have found it to be a most useful tool. It's making me rethink some of my coding tactics to TDD instead. However, I've come across an interesting problem. My test case is failing. No real concern there, but how do I…
chronodekar
  • 2,616
  • 6
  • 31
  • 36
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
49
votes
4 answers

The following constructor parameters did not have matching fixture data

I'm trying to test my controllers using xUnit but getting the following error during execution of Customer Controller: "The following constructor parameters did not have matching fixture data: CustomerController customerController" Test…
MePengusta
  • 763
  • 1
  • 8
  • 18
47
votes
1 answer

xunit constructor runs before each test

In a test class, the constructor starts before each test and the initialized data provided by the constructor isn't reachable by the following tests. I'd like the initialized data to be accessible for all tests. (be created only…
Mojtaba Khooryani
  • 1,763
  • 1
  • 17
  • 36
46
votes
3 answers

How to attach a message to RSpec check?

In RSpec: Can I attach a message to a check the same way as I would do in xUnit style test frameworks? How? assert_equal value1, value2, 'something is wrong'
Alexey
  • 9,197
  • 5
  • 64
  • 76
44
votes
5 answers

Entity Framework Core: Log queries for a single db context instance

Using EF Core (or any ORM for that matter) I want to keep track of the number of queries the ORM makes to the database during some operation in my software. I've used SQLAlchemy under Python earlier, and on that stack this is faily easy to set up. I…
codeape
  • 97,830
  • 24
  • 159
  • 188
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
43
votes
2 answers

How do you filter xunit tests by trait with "dotnet test"?

I have a .NET Core test project that uses Xunit 2.2. Some of my tests are marked with traits. [Fact] [Trait("Color", "Blue")] public void TestBlue() { } What is the right command line syntax for "dotnet test" to only run tests where the trait Color…
natemcmaster
  • 25,673
  • 6
  • 78
  • 100