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
1
vote
1 answer

How do I initialize test data to mock context using C#, MOQ and XUnit?

I have this setup in C# .NET Core 3.1. public class IngestServiceTest { private Mock mockDowJonesContext; private ILogger _logger; private readonly IngestService ingestService; public IngestServiceTest() …
Steve
  • 2,963
  • 15
  • 61
  • 133
1
vote
0 answers

Forcing xUnit tests to run as a console app

My project (Terminal.Gui) makes extensive use of console APIs (it is a 'console GUI framework'). When our unit tests run (either in VS or with dotnet test) they run in an environment where the console APIs don't work. For example, the Win32…
tig
  • 3,424
  • 3
  • 32
  • 65
1
vote
1 answer

Some unit tests runs indefinitely

In a solution, I have 600 unit tests splitted in various libraries, and 450 of them are present in a single library. When running the tests on that specific library on my computer using Visual Studio (last version), everything goes well. But, on our…
1
vote
1 answer

Xunit - Moq always returns a null value even after setup

Hi I am having an issue with my moq when I try to return data, I saw this questtion with a solution but it doesn't work on my side. Can anyone please tell me what I'm doing wrong Here is my respository private readonly…
1
vote
1 answer

Xunit inline auto data with autofixture question

i have created an custom inline auto moq attribute as below : public class AutoMoqDataAttribute : AutoDataAttribute { public AutoMoqDataAttribute() : base(() =>{ var fixture = new Fixture().Customize(new…
wywy2020
  • 13
  • 4
1
vote
0 answers

Getting the path of the file when execute from other project C#

I have created a C# library (bufferutils.cs) that required to get data from a JSON file (in the same directory) and wanted to run a unit test (bufferutilsTest.cs) using xunit. However, I have an issue with the path to get the JSON…
1
vote
1 answer

How to create fixture for sealed class with no public constructor?

I have sealed a class with no constructor which is I am referred using SDK to my project. I want to create fixture data for the class to write test but AutoFixture is giving an expectation like below. AutoFixture was unable to create an instance…
Jay
  • 65
  • 8
1
vote
1 answer

XUnit + Moq + FluentAssertions, checking for null on Task instead of proper object

I am new to unit testing and moq. Using Postman to test DeleteItemAsync(), [HttpDelete("{id:length(24)}")] public async Task DeleteItemAsync(string id) { var item = _ItemRepo.GetItemByIdAsync(id); if (item…
AndriaRose
  • 13
  • 4
1
vote
1 answer

Unit Test fails to run on solution based on Helix Visual Studio Templates

my project solution is based on Sitecore Helix Visual Studio Templates by Ander's Laub. Im trying to write Unit tests using XUnit, but none of the tests are running and not even failing. For test projects, I have tried using Project based on Class…
Suman Baul
  • 133
  • 1
  • 11
1
vote
1 answer

Why do I get System.ArgumentException in my xunit test result?

Here is the method I want to write test for: public class JobStore : IJobStore { private readonly IMongoDbContext _context; public JobStore(IMongoDbContext context) { _context = context; } public async Task
M.imp
  • 120
  • 11
1
vote
1 answer

Using Moq with Xunit - Unit testing .net core API

I'm trying to unit test a controller and I created a fake class that Implements an Interface. public class UnitTest1 { GrantProgramsController _controller; IBLGrantProgram _grant; readonly…
BGT
  • 107
  • 1
  • 8
1
vote
1 answer

How to unit test a method with hardcoded parameters?

I have a class with a method. What this method check an assembly/namespace and read all classes with the name ProductModel in that namespace: public static IEnumerable GetProductModels() { var typesList =…
avdeveloper
  • 449
  • 6
  • 30
1
vote
1 answer

How do I build tests using xUnit for an Asp.NetCore WebAPI built with Entity Framework Core and Simple Injector?

I have created an ASP.NET Core Web API using Entity Framework Core and Simple Injector. I would like unit tests using xUnit to test my controllers. I'm not sure where to begin. I believe that I have to mock a container object in my unit tests. Here…
1
vote
1 answer

How to write xUnit Test for a method which calls another method in its body?

This is the class contains EnqueueJobAsync method which I want to write test for it : public class ConsumerBaseForTesting { protected IJobStore JobStore { get; private set; } public ConsumerBaseForTesting(IJobStore jobStore) { …
M.imp
  • 120
  • 11
1
vote
1 answer

Unit testing an C# Azure Durable Function with external events

I've got an Azure Durable Function orchestrator that waits for two external events. Once they've both been received, the orchestrator calls an activity function. Is there a way to unit test this orchestrator, to verify that the activity function is…
Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110