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

Unit test FluentEmail in .NET 5 using xUnit and Moq

I'm trying to unit test FluentEmail, but I keep getting null in the send response. This is how it's set up in the ConfigureServices method: // Set email service using FluentEmail services.AddFluentEmail("sender@test.com") // For Fluent Email…
Ash K
  • 1,802
  • 17
  • 44
1
vote
1 answer

How to unit test nested method using xunit in .net core

I have below scenario public long Update(ExpenseViewModel updateModel, string einterpriseid) { long internId; ExpenseReq expenseRequest = GetReqById(updateModel.Id); if (expenseRequest != null) { int DraftStatusID =…
Manish Gupta
  • 61
  • 3
  • 14
1
vote
2 answers

how i can use hashSet in Theory inlinData

I have a test class and I want write a test for one of my functions and I have to use HashSet in [Theory] inlineData but I can't use it. [Theory] [InlineData(new HashSet() {"text1","text2"}, "str")] public void…
N Th
  • 35
  • 5
1
vote
0 answers

How to pass data from one test to another in Xunit?

I am using Playwright with C# and Xunit, but I think Selenium and Xunit users can help as well. I need to get the value of an element in one test and pass this value to another test. For example, [Fact] public async Task GetData() { var data =…
Valerie
  • 11
  • 1
1
vote
2 answers

xUnit test pass but getting "Catastrophic failure: System.ArgumentException"

When running test from command line (dotnet test) in a .net 5.0 project using xunit all tests seems to pass but the process crashes with the following message from the detailed verbosity of dotnet test: Catastrophic failure: System.ArgumentException…
Diego
  • 666
  • 1
  • 8
  • 27
1
vote
1 answer

Running an XUnit Integration Test that uses app settings from Visual Studio and from Azure DevOps

I have an Integration Test .NET 5 XUnit Project. I am using XUnit 2.4 and XUnit.Runner.VisualStudio 2.4. The Integration Tests in this project need one configuration value, the ApiUrl. I want to run the integration tests in two ways: From Visual…
Adam
  • 3,872
  • 6
  • 36
  • 66
1
vote
0 answers

xunit tests have unexpectedly stopped working in visual studio 2019 .netcore 5

My unit tests have been working fine, ive just finished some additional development and now the tests dont work at all. They arent failing becuase of changes Ive made, they've simply stopped working. Im using visual studio 2019 and version 2.4.1…
misuk
  • 133
  • 1
  • 15
1
vote
3 answers

How to compare 2 lists in xunit?

I am using Assert.Equal(expected,actual) in my unit testing.Eventhough the lists and the order are same it is failing. How to resolve this?
user16521986
1
vote
1 answer

How to exclude helper projects with "Test" in their name from unit testing?

We have a utility project named Foo.Testing.Common with helper classes for our real test projects, named things like Foo.Tests.Unit and Foo.Tests.Integration. The Common project doesn't have tests, just base classes, utility methods and the like. It…
System.Cats.Lol
  • 1,620
  • 1
  • 26
  • 47
1
vote
0 answers

Getting different HTTP responses in API integration tests based on where I place my breakpoint

I've been getting non-deterministic test results and decided to delve deeper into the issue. I've ended up on two tests behaving differently based on whether I Debug them, or just use Run. I've managed to magically fix one by deleting and renaming…
1
vote
1 answer

Rerun C# failed tests with xUnit framework in TeamCity

I'm wondering if anyone has a way of rerunning failed tests automatically on Team City? I'm using C#, XUNIT and Selenium for a suite of automated UI tests. They can be flakey and a simple rerun will pass the test on the second try. I can't seem to…
agleno
  • 388
  • 4
  • 17
1
vote
1 answer

How do I ensure a new InMemory seeded Database for each xunit test?

I am setting up integration tests for my Asp.Net Core API, using xunit. So far, I have two tests setup: public class BasicTests : IClassFixture> { private readonly…
Randy
  • 1,137
  • 16
  • 49
1
vote
1 answer

Why this Fixture is running its constructor more than once?

Why the following xUnit test doesn't get passed. ProgramFixture constructor is running 3 times, but I just want to keep the same instance for all tests, so the Count property should be: 1, 2, 3 in a sequence. Why it's giving me: 1, 1, 1 as it's…
Simple
  • 827
  • 1
  • 9
  • 21
1
vote
2 answers

How to mock MediatR to perform xUnit test for Web API Controller

I am trying to configure xUnit test for controller method. In my controller I am using MediatorR to make handler call. I have created the fixture of mediatorR Handler and set return expected object but not doing correctly and getting error on…
K.Z
  • 5,201
  • 25
  • 104
  • 240
1
vote
1 answer

What might cause an XUnit test to fail in a batch but succeed individually?

I have the following bracket balancing code written in VB.NET Imports System.Collections.Generic Public Module MatchingBrackets Private ReadOnly stack = New Stack(Of Char) Private ReadOnly closersOpeners = New Dictionary(Of Char, Char) From…
bugmagnet
  • 7,631
  • 8
  • 69
  • 131