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

How do I add more test data to assert which returns object?

I have this integration test in Xunit. [Fact] public async Task AddCampaignAsync_GivenUniqueTitle_GivenGoodDates_ShouldPass() { var campaign = new Campaign { Title = "Test", StartDate = new DateTime(2021, 6, 5), …
Steve
  • 2,963
  • 15
  • 61
  • 133
1
vote
2 answers

How to assert exception type and exception message?

This is my test method in XUnit. [Fact] public async Task AddCampaign_ReturnBadRequestWhenDateIsInvalid() { var client = _factory.CreateClient(); string title = string.Format("Test Add Campaign {0}", Guid.NewGuid()); …
Steve
  • 2,963
  • 15
  • 61
  • 133
1
vote
0 answers

How to ignore tests by category (trait) name in NCrunch

I'm using xUnit + NCrunch. I've got some tests marked as integrational: [Trait("Category", "Integration")] How do I skip those tests in NCrunch? The tests are not in the separate assembly so I cannot ignore the entire assembly completely.
Serhii Shushliapin
  • 2,528
  • 2
  • 15
  • 32
1
vote
0 answers

Mock IDynamoDBContext.ScanAsync method

I'm trying to create unit tests for the next method: public async Task GetEntityByIdAsync(Guid id) { List scanConditions = new List(); scanConditions.Add(new ScanCondition("Date",…
Hanna Holasava
  • 192
  • 1
  • 15
1
vote
1 answer

Call to FakeItEasy mocked mediatr.send method fails assertion

I am new to FakeItEasy and I am having a problem asserting if an async method has been called. It fails assertion because it hasn't been called. I have done my best to ensure the assertion matches the configured call but still no dice. …
idflyfish
  • 43
  • 3
1
vote
1 answer

Unit testing a JSON formatter?

I'm building a library, that takes a JSON string in and formats it according to template and specification, selected by the user. I've recently started on writing Unit Tests for this library, and found that creating data I can assert against in some…
fiji3300
  • 103
  • 7
1
vote
1 answer

Azure Function UnitTesting Mock HttpClientFactory

I'm trying to create a unit test for azure function and getting Unsupported expression: Non-overridable members may not be used in setup / verification expressions. Here is my Function public class EmployeeFunction { private readonly…
1
vote
0 answers

How do I get the full file name for failed .NET tests?

I've never used dotnet/.NET for unit tests before so I'm very new to how it all works. I'm starting work on an existing project with many unit tests already createdin C# and Lua, and after running those existing tests, it shows that 454 have passed…
1
vote
0 answers

Error while running threw installed application using c#

I am trying to check all installed Application and trying to uninstall the one application. But when I am running foreach loop I am getting exception My code is something like this: int a = 0; foreach (ManagementObject moobject in mos.Get()) { …
Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68
1
vote
2 answers

How to raise NotifyCollectionChangedEventArgs with XUnit

I have a class implementing INotifyCollectionChanged and I would like to test if the CollectionChanged event is raised for specific scenarios. I've tried the code bellow but I am getting compiler errors and so far I couldn't find a solution. [Fact] …
Themelis
  • 4,048
  • 2
  • 21
  • 45
1
vote
1 answer

Use file names from specific path as MemberData in xUnit. Convert `IEnumerable` to `IEnumerable`

I wanted to write unit tests for all files in specific path. For example - first run will be for file x, second for file y, etc. But I have problem with converting IEnumerable to IEnumerable: public static IEnumerable
Saibamen
  • 610
  • 3
  • 17
  • 43
1
vote
1 answer

xunit pass class method as inline data

Is it possible to pass an object method as inline data to a xunit test? I have a few object methods to set some object state that I would like to pass to a [Theory] as [InlineData] like so: private readonly SomeObject _sut; public…
Henkolicious
  • 1,273
  • 2
  • 17
  • 34
1
vote
0 answers

Having trouble triggering MassTransit consumer in xunit test

I'm having 2 issues trying to unit test some code that uses MassTransit saga state machines and consumers. I'm using Autofac as a container and xUnit as a test framework. I've got an example unit test here that illustrates both problems. When using…
Jez
  • 133
  • 5
1
vote
1 answer

How to add test authorization with inherited TestContext in BUnit?

I have an inherited TestContext in BUnit and I want to add the Testauthorization. This doesn't work: using Bunit; using Bunit.TestDoubles; public class TestClass : TestContext { [Fact] public void CompTest() { …
3r1c
  • 376
  • 5
  • 20
1
vote
1 answer

How to mock and read a cookie in xUnit?

I have a method. In that, I am reading the cookie like below, string cookieData = Request.Cookies["XXXX"]; the issue is while writing a xUnit I am getting a null. Can anyone please help me with how to do this?
Udaya
  • 33
  • 4