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 to have both xUnit and NUnit in a solution built in Azure DevOps Pipelines?

I have a C# solution where there are several unit test projects that use xUnit and an "end to end" tests project that uses NUnit. (This is intentional and fine so I'd appreciate not trying to convince me to ditch one for the other, thanks) I use an…
urig
  • 16,016
  • 26
  • 115
  • 184
1
vote
2 answers

How to moq linq expression Where()?

I have a method that modifies data in handler. if (request.Active) { var consentsToDeactivate = await _context.Consents.Where(x => x.Id != consent.Id).ToListAsync(); consentsToDeactivate.ForEach(x => x.Active = false); …
Kittu
  • 13
  • 3
1
vote
1 answer

How to mock AbstractValidator

I am failing on the BeUniqueEmail with the error message (below). How can I mock this correctly? I have included the validator and the test below. The tests passed when I removed the BeUnique email validation Message: System.NotImplementedException…
samantha07
  • 507
  • 1
  • 7
  • 21
1
vote
1 answer

How to find file path in github repository?

I have a CSV file in my GitHub repository. The program is working fine on my pc, but on Github it's not able to get the file path. I have tried changing it also, but still not working. My goal is to build and run successfully and get a green tick in…
1
vote
0 answers

Problem Referencing a File from a Project in another Project - ASP.NET Core 3.1

I have 3 projects in a solution, one is a ConsoleApp, the other two are a MyLibrary class library with one class, and a xUnit test project called Tests I have also created a Configuration file in the ConsoleApp The single class in the class library…
user1574598
  • 3,771
  • 7
  • 44
  • 67
1
vote
1 answer

Running ReportGenerator using cake build on teamcity (Exec format error)

I'm trying to generate test coverage report and view on teamcity after my project build is complete. So far I have been able to make it work on my local machine (windows) without any issue. The report is generating and I am able to view the coverage…
1
vote
1 answer

Inconsistent behavior of Directory.EnumerateFiles between .NET Core and .NET Framework

I have a project which contains two files: book.xls and book.xlsx. If I run the following code (on .NET Framework) it finds both files as expected, despite only passing .xls as extension. using System; using System.IO; using System.Linq; namespace…
Roald
  • 2,459
  • 16
  • 43
1
vote
2 answers

How to do automated integration tests using XUnit (.Net Core 2.1) and AzureDevOps?

I'm using Team Foundation Version Control as a source control for my .NET Core 2.1 project. AzureDevOps is configured in continuous integration to checkout the code and build it. We have 3 environments (Staging, PreProd, Prod). The Staging is not…
1
vote
1 answer

Using .HasDefaultValueSql("NEWID()")

When trying to write tests in xUnit I get the following error: Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: unknown function: NEWID() This appears due to the line : modelBuilder.Entity() .Property(u =>…
Scotland141
  • 314
  • 2
  • 13
1
vote
1 answer

Visual Studio 2019 suddenly requires nuget Microsoft.NET.Test.Sdk to run xUnit unit-tests

I'm using xUnit for implementing tests. I used to install the xUnit Visual Studio runner, xunit.runner.visualstudio nuget package to run tests using the VS GUI. Below is are xUnit-related branches of the dependency tree in VS. You can clearly see…
Bahaa
  • 1,577
  • 18
  • 31
1
vote
1 answer

How do I pass a parameterized value to a pytest fixture?

I'm using pytest to run tests, each with a unique account ID. Each test function requires some setup and teardown, and I switched to using fixtures according to previous suggestions. But now I need to use the unique account ID associated with each…
1
vote
0 answers

XUnit: Breakpoints in methods refrenced by [MemberData] are not working

Using .net core 3.1, I added an xunit project to a solution with the following test class: using System.Collections.Generic; using Xunit; namespace BP { public class BreakPointFails { public static IEnumerable GetData …
Allan Xu
  • 7,998
  • 11
  • 51
  • 122
1
vote
1 answer

Get an object from a service to allow test to run using xUnit and Moq

This is probably due to my lack of understanding as I'm new to xUnit and Moq but I'm trying to test a post method in my controller, however in the controller, I have this line of code: var user = await…
mattfullerdev
  • 119
  • 11
1
vote
1 answer

error CS0246: The type or namespace name could not be found (are you missing a using directive or an assembly reference?)

I am new to the .NET Core and xUnit. I would like to run xUnit tests from command line (CI pipeline). The project contains referenced dll (via in the csproj file). When running dotnet test from command…
miro
  • 131
  • 2
  • 9
1
vote
2 answers

Unit test the Get() Method using xUnit web api

Does any one know how to write a unit test (using xUnit) for the following Get() Method? Get() method is in the controller and returns list of all Categories: public class CategoryController : Controller { private MyContext x; public…
MZG
  • 327
  • 2
  • 12