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 test async exceptions in Akka.NET actor with a ReceiveAsync

I have a try/catch block in both my application and unit test. I'm trying to create a test that catches an exception being thrown in my actor. When debugging through the code I get the exception being thrown but in my test I never receive the…
Tommy Tran
  • 11
  • 3
1
vote
0 answers

Resolve dependencies on unit testing xUnit

I have a service that converts a razor view into string and I want to unit test it. Problem is that it has some dependencies in the constructor (IRazorViewEngine, ITempDataProvider, IServiceProvider) which are injected via dependency injection in…
1
vote
2 answers

How do I test the integration between the Global error handling middleware and my controller in ASP.Net Core?

I'm trying to write some test with XUnit, specifically I'd like to have a test that ensures that when a certain exception is thrown it gets remapped into a meaningful error code. I already set up the Global error handling middleware and it works…
Nardu
  • 334
  • 2
  • 14
1
vote
0 answers

Moq Setup IRepository (EF Core)

I am using Moq and trying to setup the GetPagedList mock for IRepository below is the interface i am trying to mock IPagedList GetPagedList(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable>…
Quyen T Ho
  • 55
  • 1
  • 5
1
vote
1 answer

Use class in the test's inlineData

I have used the following class as my Mocked class: public class MockData { public static MockData Current { get; } = new MockData(); public List Choices { get; set; } public MockData() { Choices = new…
user5032790
1
vote
0 answers

XUnit Deployment Directory

I would like to deploy some data items at deployment directory before running the tests in XUnit. It should be something equivalent to DeploymentItem("testdataFile.csv"). But I can't really realize the location of that directory. Is there any…
Usman
  • 2,742
  • 4
  • 44
  • 82
1
vote
1 answer

xunit InlineData tests are not found from CLI

I have found an issue with VSTS Test step where tests are rerun on failure. If a test fails with "InLineData", I found that it's not found with the test case filter. Error Message [xUnit.net 00:00:00.90] HGEM.Hub.UI.Tests: Exception filtering…
Brian Mitchell
  • 345
  • 3
  • 21
1
vote
1 answer

How to fetch categories from nunit/xunt tests using powershell?

Is it possible to fetch nUnit/xUnit list of categories using powershell? Actual problem: I mark my integration tests that use nunit or xunit with Category/Trait. Each category/trait indicates a component it tests (components are lambdas/funcs,…
nelly2k
  • 781
  • 1
  • 10
  • 28
1
vote
1 answer

xUnit - Extracting and Implementing Interfaces on Tests

Context I've just came across a scenario where I have multiple UnitTests that are similiar enough to be almost handled in a ctrl-c ctrl-v way. For example, when asserting that AutoMapper and its Profiles are valid. Question So I've been thinking if…
Alves RC
  • 1,778
  • 14
  • 26
1
vote
0 answers

Moq verify method called without mocking implementation

Currently we use Moq to verify that a method has been called with the correct parameters, however this requires the method to actually be mocked resulting in loads of bloat in the class. I would rather use the actual implementation. Can I use Moq to…
GMon
  • 638
  • 6
  • 14
1
vote
1 answer

How can I inject constructor arguments into a collection fixture?

I'm trying to implement a collection fixture where the work that the fixture needs to perform (in its constructor) requires a parameter. I want the fixture to be generic/reusable and it needs to know the Assembly of the unit being tested. How can I…
E-Riz
  • 31,431
  • 9
  • 97
  • 134
1
vote
1 answer

Net Core: Execute Dependency Injection with Xunit for Unit of Work Pattern and DBContext

I am trying to conduct dependency injection for a Base Repository with Unit of Work pattern, we are using generic repository (which was decided from company architect). For some reason nothing is saving, just wondering what is proper way to…
user11973685
1
vote
1 answer

Can I run a block of code at the beginning of only some tests in a class (from one place)?

I'm using C# XUnit in Visual Studio 2019 and I have a test class with various tests, working with databases and a web app. I'd like to run some code that sets up specific DB tables prior running the tests and also cleans afterwards. The catch is…
RegCent
  • 98
  • 11
1
vote
1 answer

How to get 100% test coverage over a DTO object class's getters when asserting function returns expected DTO object?

I'm unit testing an ASP.Net Core API by asserting that my repo layer returns a DTO object. As I'm testing behavior, I don't exactly care what values my DTO object has, so I'm autogenerating them using AutoFixture. I'm also trying to satisfy my…
1
vote
1 answer

Mocked controller object method returns Null value in Result

I am using xUnit tool to write unit test cases in Dot net core. Here in this example, I am also trying to mock protected method of the controller. public interface ITestService { string GetString(string testString); } public class TestModel { …
1 2 3
99
100