Questions tagged [unit-testing]
Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
1,810 questions
0
votes
2
answers
134
views
Is integration-testing all services the best approach?
I am building an API project, where I have a controller called C1, which calls service S1. Within this service, there are multiple method invocations to services S2and S3 and S4, as well as a call to ...
0
votes
1
answer
84
views
Automated Testing classes with an injected DbContext [duplicate]
I've been working on an implementation of a service, and have found that there are a number of operations where I need to read from a database to provide a caller with certain data or objects.
In-line ...
0
votes
3
answers
205
views
In unit testing, what is the difference between the arrange step in the AAA-pattern and a fixture?
When writing unit tests, I always doubt whether I should put preconditions into the unit test itself (as the "arrange" step) or in a fixture. Is there a difference between the two? When ...
2
votes
2
answers
163
views
Test a script reading from external source
I regularly write scripts and small tools that read data from external servers.
I am still not sure what is the most efficient and effective way to test them:
Probably the most effective way would be ...
9
votes
10
answers
2k
views
Efficiency of improving testability versus adding unit tests
My team is going to add unit tests to old code without modifying it, to pave way for future design improvements. One of the short term goals is to also reduce the number of newly introduced bugs, ...
2
votes
4
answers
200
views
Is it possible to do black box tests when I inject dependencies in the class?
This is my case.
I have a class in which I inject a service as dependency, an IService.
I want to test one method of this class. This method use one of the methods of the service.
Now I want to test ...
0
votes
2
answers
244
views
Is Spring Boot Unit Test Coverage with Integration tests only a bad practice?
I have recently come across a few codebases at work where the previous developers chose to reach the >80% coverage criteria by writing only integration tests with the @SpringBootTest annotation ...
0
votes
2
answers
233
views
Testing C# app backed by MSSQL database and Entity Framework - seeking advices for going with "test double" approach
I am new to C#, and Windows (coming from Python, Linux background). I need to add tests
to an existing C# codebase, which relies on a MSSQL database and Entity Framework.
In my old days when testing ...
2
votes
3
answers
461
views
How to unit test private method that is used by many public methods under a common API without duping the tests
This question is a more specific version of the one I posted last week.
Let's say I have a complex data structure that is posted into a bunch of different services.
The interface of all services looks ...
0
votes
4
answers
233
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 ...
1
vote
1
answer
176
views
NUnit testOf attribute usage
What are the use cases of TestOf? I'm new to NUnit testing and from what I have seen, most people don't use this attribute that much.
From my experience, TestOf helped me to quickly identify what ...
5
votes
5
answers
715
views
How to test for performance regression?
I am working on a refactor on a certain package (I can give details if asked). The package involves a clever lazy evaluation of a sort of nested sequence of arithmetic operations. If the numerical ...
0
votes
2
answers
444
views
Origins of Unit Testing in hardware?
According to the Wikipedia entry for Unit Testing, it is defined as a technique for testing components of a system in strict isolation from each other, and it is described as having been expressly ...
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 ...
1
vote
1
answer
606
views
Should I skip unit tests if integration tests cover the same scenarios?
I have a service method called acceptOrDenyJoinRequest that follows a logic similar to this flowchart (green boxes are ignored in code, and the light gray box calls an external service). According to ...
1
vote
3
answers
486
views
Concurrent, identical instances as an integration test
Over the years it's becoming clear to me what's an integration test and what's a unit-test.
I understand some people more or less settle on their definitions but to be brief I consider testing one ...
2
votes
5
answers
498
views
How to follow Outside-In TDD with Micro-services and Micro-frontends?
I was exploring TDD, specifically the Outside-In TDD pattern, where we need to write the acceptance (integration) test and then jump on to granular unit tests to implement the feature and make the ...
4
votes
8
answers
3k
views
Should I write and commit unit tests for minor changes and bug fixes?
For example, if the change is "return users' full names instead of just last names", is it worth it to add a test for it? Would it make the test suit fragmented and confusing?
Context: My ...
3
votes
2
answers
688
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 ...
2
votes
1
answer
784
views
Approach to software testing with docker
When discussing the testing approach, we had disagreements.
We develop software that we package into an image and distribute. We have two suggestions for testing:
Build a separate image with a test ...
1
vote
3
answers
826
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 ...
3
votes
1
answer
278
views
Unit Test Against In-Memory vs Real Database for SwiftData Applications
I am writing unit tests for my SwiftData application. Currently, I am using in-memory database, which get reset after every test. What benefits will I gain if I start using real database? My main ...
-3
votes
1
answer
112
views
Testablilty of setup with builder pattern for configuration
We have built a library which can handle RESTful requests based on configured endpoints.
A fluent builder is being used to create endpoint definitions (configurations). These definitions are bound to ...
4
votes
5
answers
414
views
Does testing the public surface of a class test the behavior of code or the way it is written?
A follow up question to How do unit tests facilitate refactoring without introducing regressions?.
I said that integration tests test the behavior of the code, while unit tests, being tied to ...
0
votes
1
answer
114
views
Testing Boundaries on Publisher/Subscriber patterns
I work with a integration project based on Publisher/Subscriber pattern whose subscriber end feeds a staging database which stores data to be pushed to another application. The staging database has ...