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

.NET CORE unit test - mockRepo.Setup for repository always return NULL

I have a simple method which is using an interface to call the repository, method is working just fine but whenever I try to mock Login method and return something fake, it just return null for me. my method [HttpPost] public…
Arash
  • 1,692
  • 5
  • 21
  • 36
1
vote
1 answer

Function under test "foo" calls external function "bar(baz)" multiple times => How can return value of "baz" be modified specifically for each call?

Assume that I have the following function "foo" which I want to unit test: class FooClass { IBar _bar; Foo(IBar bar) { _bar = bar; } void foo() { byte[] someBytes; someBytes =…
RadioMan85
  • 337
  • 1
  • 11
1
vote
3 answers

Create a list with specific values with Autofixture C#

The Model has properties Id, Code etc. I want to create 4 data with specific different codes. var data = _fixture.Build() .With(f => f.Code, "A") .CreateMany(4); This results in all 4 data with Code "A". I…
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
1
vote
2 answers

xunit 2.4.1 use cli dotnet test --collect:"Code Coverage" not generate coverage xml

I used dotnet test --collect:"Code Coverage" PS D:\git\MiniExcel\tests\MiniExcelTests> dotnet test --collect:"Code Coverage" #... Data collection : Unable to find a datacollector with friendly name 'Code Coverage'. Data collection : Could not find…
Wei Lin
  • 3,591
  • 2
  • 20
  • 52
1
vote
0 answers

How to effectively run .net core unit test with selenium, from published web app

I have a .NET Core v2.2 application. I am trying to start Selenium UI tests, built on top of unit testing project (tried using NUnit, xUnit). The tests can be started locally from VS(using TestExplorer), or from started locally .NET Core 2.2…
kvadrat4o
  • 11
  • 1
1
vote
1 answer

The workspace you are trying to open is incompatible with the current dotMemory version

I have created a new XUnit Tests Project with .Net 5 target framework with one test class public class SomeTests { private readonly ITestOutputHelper output; public SomeTests(ITestOutputHelper output) { this.output = output; …
1
vote
1 answer

Auto increment primary key in mocked db context

Does anyone know how can I have auto increment primary keys in my mocked db context? I am unit testing a method and when I want to add two items to my mocked db context and I get an error saying "An item with the same key has already been added". so…
MZG
  • 327
  • 2
  • 12
1
vote
0 answers

Unit testing theories on collections xUnit

Original question Let's say I have a class method GetAge(DateTime dateOfBirth) and I want to test if the age that comes out is correct. To do this, I create a helper method called GenerateDateOfBirth(int age) that returns a date of birth that should…
JansthcirlU
  • 688
  • 5
  • 21
1
vote
2 answers

Azure devops: Screenshot are not showing in attachment tab

I am trying to add failed test attachments in the Test tab in Azure DevOps using VS test task. I am calling the Create Test Result Attachment rest api, $AzureDevOpsPAT = {PAT} $AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' +…
1
vote
2 answers

C# Xunit testing a list that must contain 4 of each value

So I'm practicing unit testing (Xunit) and C#. I'm making a poker game console application. I have a card deck that is a list of 52 cards. The list is made of Card class and each card has an int value that represents what card it is eg value 1 is…
HelsiP
  • 26
  • 4
1
vote
1 answer

Writing Mocks for delegates in an Azure Function using Moq

I have an Azure function which basically gets invoked upon HttpRequest to the endpoint. This function then makes calls to relevant sections in the database based on CREATE or UPDATE message that is passed in the payload. public class InboundEvent { …
this-Me
  • 2,139
  • 6
  • 43
  • 70
1
vote
3 answers

How to do integration testing on an external API with ASP.NET Core

I'm trying to do some integration tests on an external API. Most of the guides I find online are about testing the ASP.NET web api, but there's not much to find about external API's. I want to test a GET request on this API and confirm if it passes…
Bram
  • 669
  • 3
  • 12
  • 25
1
vote
2 answers

How to test web api method with xUnit and Moq when there is "this" keyword

I am trying to test the web api method with xUnit and Moq but there comes a situation as it is using "this" keyword. Please see the code. Web API Inteface public interface IRepository { IEnumerable Reservations { get; } …
yogihosting
  • 5,494
  • 8
  • 47
  • 80
1
vote
1 answer

Mock returns null when mocking using Moq

I might be missing something obvious here. Using Asp.Net core background service. The simplified setup is as follows: SUT public class OrderService: BaseOrderService { IConsumer _consumer; public OrderService(IBuilder…
Jinish
  • 1,983
  • 1
  • 17
  • 22
1
vote
3 answers

SQLite in-memory databases testing an EF Core application with temporal tables

We are using system-versioned temporal table in our Entity Framework Core application. This works really well but we are experiencing problems when creating a…
Ogglas
  • 62,132
  • 37
  • 328
  • 418