All Questions
200 questions
0
votes
4
answers
232
views
Avoid Test duplication if a function created via TDD has an implementation detail that is later used in other functions
Lets say I have an API with two functions:
CreateNewMachine(CreateMachineCommand createMachine);
EditExistingMachine(EditMachineCommand editMachine);
The internal logic of both functions should be ...
12
votes
9
answers
8k
views
is it okay to mock a database when writing unit test?
I read an article about unit testing by Vladimir Khorikov, written in 2020. Here is The Article
https://vkhorikov.medium.com/dont-mock-your-database-it-s-an-implementation-detail-8f1b527c78be
It said ...
-3
votes
1
answer
142
views
Mock an API for development purpose (no testing)
If I want to implement a connection from my software to an API, which is documented but not accessible yet, what is a common way to imitate the API until it is available?
My first idea was to mock the ...
0
votes
3
answers
289
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
680
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 ...
0
votes
2
answers
2k
views
Setting up private properties for unit testing
I'm doing some TDD practice for my own learning.
I'm trying to figure out how to transparently set up private properties of an object to support testing.
I have a binary tree node:
internal class Node ...
1
vote
1
answer
218
views
Benefits of resolving dependencies with IServiceCollection and IServiceProvider for Unit Tests instead of inheriting mocks from a base test class
Articles such as this point out some of the pitfalls of manually instantiating dependencies in UTs, while showing some of the benefits of doing it, instead, with the .NET's dependency container by use ...
0
votes
1
answer
2k
views
Why are sealed classes not allowed to be mocked?
Using Moq framework, it is not allowed to mock a class in C# which is sealed. Same goes for many other frameworks as well. But why is it not allowed?
-1
votes
1
answer
733
views
Alternatives to using mock libraries such as Mockito in unit testing
Typically, when writing unit tests I tend to need to stub out collaborators and also mock some behavior in one or more of the collaborating objects. Say if I am testing a Service that is using a Dao, ...
2
votes
3
answers
311
views
How do you decompose big object for testing?
I have a package that provides an object with quite a lot of features owned by it.
Let us say the object is an HTTPServer, and when the user initializes it by providing config and a request handler ...
1
vote
1
answer
170
views
How do I mock API responses with security in mind?
My team and I are beginning to mock our API responses in our iOS app so we don't have to worry about our backend being up when testing.
I have conditional compilation directives based on the ...
2
votes
2
answers
304
views
Where to put interface files for mocking aka what are best practices for organizing interfaces in a C#/.NET Core project with NSubstitute, Moq etc.?
Question
I'm working on a C#/.NET Core project, and I'm looking for guidance on organizing interfaces, especially when it comes to using NSubstitute, Moq or other libraries for mocking, because there ...
1
vote
3
answers
189
views
Isolate or Redundant Test?
I have lots of code like the following. An "Entity" type that has some numerical properties. To be able to reuse the arithmetic I write the arithmetic functions against an interface. I use ...
1
vote
1
answer
210
views
Abstracting away small function inside a class for easier mocking during testing
I have a function that looks roughly like this:
async function getValue(connection: Connection): Promise<number> {
const value = await connection.getValue();
return value < 0 ? value :...
-1
votes
3
answers
137
views
Code Coverage and Unit Tests nomenclature [closed]
About tests:
I have the following view on nomenclature:
Unit tests are the kind of testes where you have a function
ExtractBacon, where there is a function with an entry parameter Pig
and a return of ...