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

xUnit comparing object equality

I have this class with its constructor public class BankAccount { public int Id { get; private set; } public int BankAccountNo { get; private set; } public decimal Balance { get; private set; } public BankAccount(int…
Steve
  • 2,963
  • 15
  • 61
  • 133
1
vote
2 answers

How to convert JSON string to object compatible with xUnit/.NET Core API?

In my xUnit test case I am reading JSON from a file, loading it in string and passing it a function that is originally called by controller. My controller is: [HttpPost] public List Post([FromBody] object ds) { var result =…
variable
  • 8,262
  • 9
  • 95
  • 215
1
vote
2 answers

How does xUnit runner handle static methods w/static class constructor?

If I have a class with static Facts (test methods) and the class has a static constructor, is the constructor called for each Fact or only once for all Facts in a class? I guess it depends on how the runner loads/unloads test classes?
Suraj
  • 35,905
  • 47
  • 139
  • 250
1
vote
0 answers

xUnit - got stuck at how to print out anything from static method

Using MVS 2015/ Speckflow (2.4.1)/ xUnit (2.0.0) Please help to printout anything from static method with xUnit framework: namespace UnitTestProject2 { [Binding] public class SpecFlowHooks { private readonly ITestOutputHelper…
Alexander
  • 11
  • 1
1
vote
0 answers

XUnit tests output in Output Window but not in Test Explorer and cannot be debugged

I have an XUnit test which is failing with a nullreference exception, probably there's some property on one of the objects that I need to give a value for but haven't. That would be easy to figure out, except attempting to debug tests isn't working.…
user973223
  • 127
  • 1
  • 8
1
vote
1 answer

Get configuration in Unit Test

I can't figure out how to get some configuration I'm using by following the IOptions pattern. The service I want to test is the next one: private readonly Dictionary _errors; public UserService( …
Ferran R.
  • 174
  • 1
  • 12
1
vote
1 answer

How to create new instances of objects with custom SpecimenBuilder with AutoFixture

Currently I have such code: private ConnectedClient WithConnection(IConnection connection) { var builder = new ClientWithConnectionSpecimenBuilder(connection); Fixture.Customizations.Add(builder); var client =…
Ivan Zyranau
  • 879
  • 2
  • 14
  • 33
1
vote
1 answer

Best way to test logging?

My code logs with an ILogger like this: public class Calculator { private readonly ILogger _logger; public Calculator(ILogger logger) { _logger = logger; } public int Sum(int x, int y) { int sum…
PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176
1
vote
1 answer

Xunit how to test that a decimal property and string are null

I want to be able to write a unit test for when a decimal value is null and the string value is null. private void CompareAsNumbersIfNotEmpty(decimal? actual, string expected) { if (expected == null) { }else if (expected.Length > 0) …
gkkkab
  • 109
  • 2
  • 7
1
vote
1 answer

Is it possible to add inline C# objects to a theory in xUnit?

I have some custom C# objects which I want to pass as InlineData arguments in xUnit's Theory. I tried the answer in this question without any success since my objects are not strings and therefore cannot be created as compile time constants (An…
Themelis
  • 4,048
  • 2
  • 21
  • 45
1
vote
1 answer

XUnit Using a Dictionary As MemberData

I am having trouble with the syntax of how to get an XUnit Test Method to accept a dictionary as a paramater. This is my code which is broken: Public static Dictionary vals = new Dictionary { { "a", "1" }, { "b", "2"…
Paul Stanley
  • 1,999
  • 1
  • 22
  • 60
1
vote
1 answer

CS0246 error while trying to create xUnit tests

I'm not even trying to test anything there yet, just wanted to create an instance of class Book(that I would like to test in the future) in my testing BookTests.cs file. I've added reference to GradeBook.Tests.csproj as whole source code to…
suszonko
  • 15
  • 3
1
vote
1 answer

Integration testing calls with simulated delays

I'm testing an asp.net Core 2.2 WebApi backend which uses EF Core for data persistance. The solution is arquitected using CLEAN arquitecture with a repository/service pattern making every component individually testable. My integration tests (using…
akseli
  • 1,416
  • 14
  • 22
1
vote
1 answer

XUnit: How to assert exception thrown by the controller in ASP.NET Core

I have a method inside the controller, which does some checks when the check is not true, it will throw an error. How I will catch that error thrown by the API with the specific message? I`m confused about how to make those types of…
Csibi Norbert
  • 780
  • 1
  • 11
  • 35
1
vote
1 answer

How to test that an event will not be fired in xUnit?

I have two questions. Does it make sense to test that an event will not be fired? If yes, what is the best way to accomplish that using the xUnit framework? For example, I have a class with a single property Mark, public class Box :…
Themelis
  • 4,048
  • 2
  • 21
  • 45