3,341 questions
4
votes
0
answers
212
views
`dotnet test` is inconsistent when it comes to showing the total number of unit tests at the end
I have a solution with many projects. When I run dotnet test, it selects all my xUnit projects and seems to correctly execute all of them. But at the last line of what dotnet test prints, the number ...
2
votes
2
answers
104
views
Are these unit tests using Moq testing anything?
I am attempting to test a repository method using a moq with a setup in the test. As far as I can tell, this is not testing the method but only testing the test.
Here is an abbreviated version of the ...
1
vote
0
answers
57
views
System.AccessViolationException occurs when running a C# Godot unit test for Node2D object
I am building a card game using Godot 4.5, with C#. I am trying to unit test a Card object that inherits from Node2D, but when I attempt to run the test, I get the following exception:
Exception has ...
0
votes
0
answers
104
views
xunit test in VSCode on Windows doesn't stop on breakpoint
I am trying to use XUnit for testing my f# code.
module UnitTest1
open Xunit
open Program
open System.Diagnostics
[<Fact>]
let Test1 () =
Debugger.Break()
Assert.True(true)
The test ...
0
votes
0
answers
33
views
Pass `string[][]` as `InlineData to xUnit Theory? [duplicate]
In an xUnit theory I'd like to send an InlineData parameter of type string[][]. I can't seem to get it right. Is it doable, and if so, how?
I would expect this to work at least:
[InlineData(new string[...
0
votes
0
answers
70
views
How to create integration tests with Keycloak and xUnit?
I'm creating a new project with Keycloak and .NET Core 9. I've managed to get it working with my application, but I need to make it work with my integration tests.
To integrate authorization and ...
0
votes
0
answers
44
views
Visual Studio running ALL tests even though I only right-click ran one
I have a maddening issue that I've been unable to find any help with doing the usual googling.
Every time I go to Test Explorer in visual studio and select/right-click run a single unit test, it will ...
0
votes
0
answers
41
views
xUnit.net v3 In-Process Runner how to show the names of failed tests
When I run a xUnit.net v3 project on the command line it will list failed test but not passed tests. Is there an option or flag that I can set to show the names of the passed tests?
C:\src\xxx\yyy\...
0
votes
2
answers
72
views
In XUnit, can you capture calls to Console.Out from a Console app under test and make assertions on them?
Given a simple .NET Console App like this:
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
Can I write a unit test ...
0
votes
1
answer
136
views
How to mock IDataReader to get more than 1 record in XUnit testing
I developed an ASP.NET Core 8 MVC project and want to test all action methods using XUnit testing. But when I want to read data from the database using IDataReader, the code throws a ...
0
votes
1
answer
105
views
How to unit test ConvertUrl from SelectPdf.HtmlToPdf
How to unit test this method:
public PdfDocument GetPdf(string requestUrl)
{
var converter = new HtmlToPdf();
var response = converter.ConvertUrl(requestUrl);
return response;
}
...
0
votes
0
answers
46
views
Filter tests by Xunit.TraitAttribute in VS Code
I have two XUNIT trait categories on my tests.
[Trait("HasDelay", "Yes"/"No")]
[Trait("Category", "Integration"/"Unit")]
I'm struggling to ...
1
vote
1
answer
581
views
How to get TRX output from C# unit tests using Microsoft.Testing.Platform?
I am trying out the new-ish Microsoft.Testing.Platform in my C# unit tests. By default the platform does not produce TRX output, but there is an extension that allegedly provides TRX support: ...
0
votes
1
answer
100
views
How to write a conceptually correct unit test for API method with Linq?
I'm learning how to write unit tests, please don't judge heavily. I have an API method below, written in C# for .NET 8.0, which I want to test. I use XUnit, Entity Framework Core 8, SQL Server 2019. ...
0
votes
0
answers
56
views
Running a Web API as a Process with a real tcp socket .NET
I am trying to run a test for my project that will need the whole API app to run by using process to start and run the application on a real TCP socket for eventual pact testing.
The API seems to ...
2
votes
0
answers
52
views
Is there any a.k.a. CompositeCustomization, but for IFIxture
I have next Fixture configuration code:
private static IFixture CreateFixture()
{
var fixture = new Fixture();
fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList()
....
0
votes
0
answers
96
views
Intermittent Login Failed errors with Integration Tests using SQL Server TestContainers with transactions
I'm spinning up a WebApplicationFactory against our main API's Program.cs, mocking out services as needed, and then calling several integration tests against different endpoints.
For the database, we'...
2
votes
0
answers
61
views
XUnit run tests parallel and it cause problems with EF Core and Sqlite
I am using XUnit with EF Core and Sqlite in .NET 9.
During testing, several tests add data to the database and since they do it in parallel and add data in parallel, the tests get unexpected data from ...
2
votes
1
answer
174
views
How do I isolate MassTransit test harness per test when using a shared SQL container and scoped transactions in xUnit?
I have an integration testing setup in .NET using xUnit v3, Testcontainers (for SQL Server), and MassTransit. My goal is to have:
A single SQL container spun up once at the assembly level (using [...
0
votes
0
answers
19
views
How to remove class name from BDDFy Standard Output
I have a BDDfytest
.....
This.Given(_=> SomeInput(1))
.And(_=> AnotherInput(5))
.Bddfy():;
.....
which generates standard output text like this
Scenario: do something useful
Given ...
0
votes
1
answer
84
views
How to write test case for QueryMultipleAsync
I tried to write test case for my DataAccess method containing QueryMultipleAsync but it being failed showing the error :
Error :
Message:
System.NotSupportedException : Unsupported expression: gr =&...
2
votes
1
answer
241
views
Cannot remove DBContext from DI
I am writing XUnit integration tests for my ASP.NET Core Web API. I reconfigure my app in CustomWebApplicationFactory to replace original DbContext with the EFCore InMemoryDataBase like this:
...
0
votes
0
answers
107
views
How can I set/unset an environment variable in VS Code, so that it will take effect for xUnit test runs?
In my test suite, I'm dynamically skipping tests based on the presence of an environment variable called ASSSETGOV_TEST_MANUAL. This is a common pattern used to skip tests that should only be run ...
0
votes
0
answers
22
views
Error while testing PUT (with EntityState.Modified) request to a database using InMemory, xUnit in .NET unit tests
I do not have much experience with testing in .NET. I ran into an issue that I do not understand how to solve. Please advise where I can read about it.
I have a backend code that works with a simple ...
1
vote
2
answers
138
views
Integration tests failing because 'The following constructor parameters did not have matching fixture data'
I’m trying to create integration tests in .NET 9 C# using xUnit and TestContainers. However, whenever I run the tests, a new database container is created for each test class. I want to initialize ...