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
0 answers

How to create ".dll" file from xUnit project, using msys2 and mono?

I have xUnit project in .Net Core framework and what I need is to create the .dll from this project, using the console. The project has many classes for test cases. I am using mono and msys2 and I need to compile the project using these…
delux
  • 1,694
  • 10
  • 33
  • 64
1
vote
3 answers

Using xunit or nunit as test runner framework

I'll start with an problem. I have a little library. It goes through a list of urls in text files and create assertions depending on the url returns 200 or not. The goal is to make a test runner like Reshaprer, Testdriven.net or a CI server like…
Emil C
  • 1,315
  • 4
  • 15
  • 27
1
vote
0 answers

Setup add function in Mock DbSet with Moq (Entity Framework)

I'm new to mocking, and I'm trying to create a mock DbContext for testing select, add, update, delete. The mock for selecting is working, but when I'm trying to add the 'add' function in the setup, I'm getting the following error in my return value…
Niels
  • 416
  • 5
  • 22
1
vote
0 answers

Integrate AppMetrics into a xUnit only project

I have a .NET Core 3 solution which consists of a xUnit test project and a .NET Standard class library. The sole purpose of this solution to run integration tests for our ecossystem. Currently, it looks like this: My next goal is to integrate…
1
vote
2 answers

Does ClassData in xUnit Test accept arguments? C#

I was writing an unit test for my application. For now I am using Theory with ClassData to create a data-driven unit test. I was wondering is ClassData able to accept parameters so that I can alter the test data based on the input from the…
Sivvie Lim
  • 784
  • 2
  • 14
  • 43
1
vote
1 answer

How do I test "should not contain" using FsUnit.Xunit?

I am trying to test that a collection does not contain a value using FsUnit.Xunit. open FsUnit.Xunit [] let ``simple test`` () = let xs = [ 1; 2; 3 ] xs |> should contain 1 xs |> should not contain 99 // Not real code I have also…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
1
vote
1 answer

Method mocked with NSabstitute returns '0' instead of HttpStatusCode.OK

Why do I get int value '0' after mocking my service and specifying return value as HttpStatusCode.OK? First I mock my service : private readonly IService service= Substitute.For(); Then in the test : var statusCode =…
mike
  • 1,202
  • 1
  • 7
  • 20
1
vote
1 answer

XUnit: ICollectionFixture instance not getting shared between test methods of a test class

I have created ICollectionFixture implementation in hope to create a database instance and share it among various test classes. But, its just not happening and the DBContext gets created on every test method call. On debugging, I can clearly see…
Rahul Ranjan
  • 1,028
  • 1
  • 10
  • 27
1
vote
0 answers

xUnit System.TypeLoadException when implementing interface with dynamic method param

I have a referenced nuget package that contains an interface: public interface IMyInterface { bool Initialize(Dictionary initArguments); } In my solution I have this implementation: public class MyImplementation : IMyInterface…
aperezfals
  • 1,341
  • 1
  • 10
  • 26
1
vote
1 answer

How do I write a unit test for this method that is called inside a loop?

I'm trying to test a method using xUnit and Moq. The public void DoSomeWork_Verify_GetJsonDataString_is_called() test is failing. Please can someone let me know what I am missing in the test/mocking. The GetJsonDataString is an API call that returns…
cmoe
  • 141
  • 3
  • 12
1
vote
1 answer

Redirecting original c# program output to Xunit output

Is there a way to redirect the original program output to XUnit output? All i could find is how to print output from XUnit tests (see here) With "original output" i mean that for each time i write Console.WriteLine or similar in my program i want…
Acerbic
  • 100
  • 1
  • 9
1
vote
1 answer

How to write a test with xUnit in .NET Core using Dapper.Contrib?

I used Dapper.Contrib in my Asp.Net Core Web API project. I encountered a problem while writing a test with xUnit in this project. For example, here is my method that adds records to my data layer. public async Task AddAsync(User entity) …
1
vote
2 answers

Where to create HostBuilder and avoid 'The following constructor parameters did not have matching fixture data'

I took a legacy .NET framework application, that consisted of class libraries and a unit test project only, and converted them all to .NET core 3.1. I can't seem to execute or bootstrap the unit tests with the .NET core method of using the…
Seany84
  • 5,526
  • 5
  • 42
  • 67
1
vote
1 answer

Test methods are not executed when associating same test method to multiple test cases in VSTest running XUnit tests

We have an ASP.Net application and UI tests written with xUnit. Test plans are in VSTS, and in some cases same xUnit test method is associated to multiple test cases. An azure build pipeline executes these tests using VSTest. The problem is when…
Baga
  • 1,354
  • 13
  • 24
1
vote
1 answer

vertx unit test not executing, timeout exception

I have the below simple retry class. This class will retry a given promise for a couple no of times(retryCount), with a given delay(delay), if it succeeds within the retry count, it passes, else it fails. public class SimpleRetry { private final…
Kaushik Das
  • 99
  • 1
  • 1
  • 8