Skip to main content

Questions tagged [xunit]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
3 answers
128 views

.Net 8 XUnit: How to mock MySql in a CQRS API using integration tests?

This is a rewrite of my own .Net 8 XUnit: Should my tests use real data or how to mock MySql with CQRS? in a much more clear way: The reason for rewriting my previous question is because in the ...
3 votes
2 answers
348 views

.Net 8 XUnit: Should my tests use real data or how to mock MySql with CQRS?

I'm creating tests for our .Net 8 API. We use MySql for data storage and CQRS pattern for queries. In my personal opinion, I shouldn't use the real database for testing, because you will use an ...
1 vote
3 answers
154 views

Creating Unit and Integration Tests with Database elements

This is something that I've heard a number of opinions and theories about, but I'm still torn on how to go forward. For context, this particular issue deals with the following technologies, in case ...
121 votes
19 answers
15k views

What is the point of unit tests?

I've been a software developer for 20+ years, although it's been an unusual career. I've mostly worked on either legacy projects, or small standalone, non-public-facing apps and so only a couple of ...
0 votes
1 answer
273 views

Best practice when it comes to using XUnit and prepping/ rolling back test accounts before and after running tests

I am writing integration tests via unit tests by using Xunit. (the specific testing framework is not set in stone, Xunit is being used simply because it has been used before in this project team) The ...
20 votes
8 answers
8k views

Why assert for null on a object before asserting on some of its internals?

Let's consider the following test. [Fact] public void MyTest() { // Arrange Code var sut = new SystemWeTest(); // Act Code var response = sut.Request(); // Assert ...
7 votes
6 answers
5k views

How to Differentiate Unit Tests from Integration Tests?

In my C# solution, I have a Tests project containing unit tests (xUnit) that can run on every build. So far so good. I also want to add integration tests, which won't run on every build but can run ...
66 votes
5 answers
21k views

Is the usage of random values in unit testing a good practice? [duplicate]

Having worked in complex solutions that had Unit Tests and Integration Test in the CI/CD pipeline, I recall having a tough time with tests that failed randomly (either due to random values being ...
4 votes
2 answers
2k views

Unit testing a generic method not caring about the generic type

I have the following code public class MyCollection<T> { public void Add(T obj) { ... } public int Count { get; } } and the following unit test to check whether Add increases the Count ...
1 vote
4 answers
3k views

Should Unit Tests share the Same Data set?

We are writing application service tests across our Data Service Class. Currently writing tests liking add Product, remove Product, check for inventory after sale, etc. They are all using the same ...
-1 votes
1 answer
177 views

Should I have “shouldfail” unit test and “shouldpass” for all methods in TDD?

Here is my class library code which I have C# and xUnit. namespace XUnitSample.ClassLib { public class DataAccess : IDataAccess { public void AddPersonToPeopleList(List<Person> ...
1 vote
1 answer
452 views

xUnit and MOQ Code Structure and Setup in C# .NET Core

I am trying to create a simple setup for xUnit. At the moment, the function does not access to database. So, here is my structure: I have 2 projects in my solution. First is my class library which is ...
-2 votes
1 answer
57 views

Xunit TDD - second rule

What is the meaning of: You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failure by Robert Martin on TDD? Is it write only the needed ...
4 votes
2 answers
5k views

Are in-memory database a form of integration tests?

I have looked through most of the answers given regarding using in-memory database for unit test, but I could not find one that was clear to me. I am writing some unit tests to cover some of our ...
0 votes
3 answers
551 views

Is this proper way to unit test?

I'm trying to unit test some repositories and have no idea what I'm doing if someone could point in the right direction that would be good, currently, I'm testing behaviour of creating a new user ...
0 votes
1 answer
203 views

Unit/Component testing using In Memory DB

I am writing Unit/Component test using In Memory DB. When I write Unit/Component test, I came across with the following question. I have the following two BL methods. ToCreate ToGet So when I ...
0 votes
3 answers
1k views

xUnit Should I Test Method Internal Work Or Only Result?

Let's take this unit test. Unit testing guidelines state that I should only have 1 assert per test, unless I'm testing the state of an object. In this case, Muxer.Muxe is a wrapper around FFMPEG that ...
28 votes
2 answers
4k views

Is a Unit test considered brittle if it fails when the business logic changes?

Please see the code below; it tests to see if a person with Gender of female is eligible for offer1: [Fact] public void ReturnsFalseWhenGivenAPersonWithAGenderOfFemale() { var personId = Guid....
2 votes
1 answer
94 views

Keep unit tests common in separate library or duplicate?

Sometimes, ex. when using common mocks (same for data access layer as for presentation, I use often xunit ClassData), I come to the moment when I either copy common code to new unit test library or ...
11 votes
1 answer
347 views

Integration tests in OSS projects - how to handle 3rd parties with authentication?

One of my (open source) hobby projects is a backup tool which makes offline backups of repositories from GitHub, Bitbucket etc. It calls the hosters' API to get a list of repositories, and then it ...
26 votes
4 answers
23k views

What is the best unit test framework for .NET and why? [closed]

It seems to me that everyone uses NUnit without even considering the other options. I think this is because: Everyone is familiar with it already so they won't have to learn a new API. It is already ...
2 votes
3 answers
2k views

Split tests by method or behavior? [duplicate]

I have a method that I need to test that has multiple cases that need to be tested, and each case requires a few lines of code to test. Before long the test function is 50 lines long and it is a bit ...
6 votes
2 answers
931 views

How are design-by-contract and property-based testing (QuickCheck) related?

Is their only similarity the fact that they are not xUnit (or more precisely, not based on enumerating specific test cases), or is it deeper than that? Property-based testing (using QuickCheck, ...
1 vote
2 answers
539 views

Testing Framework Selection: xUnit family theory

Background: I am familiar with xUnit family frameworks and have had experience with (shunit2, PhpUnit and simpletest). I am currently trying to find a testing framework for C++. I did a quick search ...
15 votes
6 answers
6k views

Why don't xUnit frameworks allow tests to run in parallel?

Do you know of any xUnit framework that allows to run tests in parallel, to make use of multiple cores in today's machine? If none (or so few) of them does it, maybe there is a reason... Is it that ...
3 votes
4 answers
1k views

When, Where, and How to Unit Test [duplicate]

I'm very familiar with xUnit frameworks and I try to implement unit tests on every project I start. Somewhere along the way, I realize that I'm writing the same tests over and over again, and then I ...