Questions tagged [xunit]
23 questions
119
votes
19 answers
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 times has it been mandated by my employer to…

Edwardo
- 927
- 2
- 3
- 5
64
votes
5 answers
Is the usage of random values in unit testing a good practice?
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 injected or because of the async nature of the process…

Vinicius Scheidegger
- 645
- 1
- 4
- 7
28
votes
2 answers
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.NewGuid();
var gender = "F";
var person = new…

w0051977
- 7,031
- 6
- 59
- 87
26
votes
4 answers
What is the best unit test framework for .NET and why?
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 set up with their continuous integration server…

Nobody
- 2,613
- 1
- 22
- 25
19
votes
8 answers
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
response.Should().NotBeNull();
…

BAmadeusJ
- 316
- 2
- 7
15
votes
6 answers
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 tests are usually so quick that people simply…

Xavier Nodet
- 3,684
- 2
- 26
- 33
11
votes
1 answer
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 uses Git/Mercurial/whatever to clone/pull the…

Christian Specht
- 1,863
- 3
- 15
- 23
7
votes
6 answers
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 on request. Where do you put those, and how do you…

Etienne Charland
- 361
- 3
- 10
6
votes
2 answers
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, ScalaCheck, etc) seem well-suited to a functional…

Todd Owen
- 173
- 5
4
votes
2 answers
Unit testing a generic method not caring about the generic type
I have the following code
public class MyCollection
{
public void Add(T obj) { ... }
public int Count { get; }
}
and the following unit test to check whether Add increases the Count property by one:
[Fact]
public void…
user277671
3
votes
2 answers
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 codebase. The codebase is written in ASP.NET Core and…

elfico
- 143
- 2
- 6
3
votes
4 answers
When, Where, and How to Unit Test
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 run into a really difficult to test method or a…

Naftuli Kay
- 1,601
- 2
- 16
- 23
2
votes
1 answer
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 create "UnitTestsCommon" project.
I cannot find…

Piotr Falkowski
- 197
- 7
2
votes
3 answers
Split tests by method or behavior?
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 difficult to find the failures. (No, this function…

J Atkin
- 163
- 7
1
vote
4 answers
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 data storage in a list, BeforeEach Method.
When they…
user375708