Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

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.

Filter by
Sorted by
Tagged with
0 votes
2 answers
124 views

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 ...
Héctor Iglesias's user avatar
5 votes
5 answers
573 views

Imagine I have a function like this (written in Java): void sayHello(String firstName, String lastName) { if (firstName == null) { throw new IllegalArgumentException("first name is ...
J-bob's user avatar
  • 357
0 votes
1 answer
83 views

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 ...
Lily Smith's user avatar
1 vote
1 answer
251 views

We have a CAD software extension, where you can draw products like walls, doors, windows, etc., and you can export the drawing as an order, which contains the parts and costs. As part of this export, ...
Divan's user avatar
  • 369
0 votes
3 answers
205 views

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 ...
PieterV's user avatar
  • 233
4 votes
3 answers
313 views

Not long ago while I was exploring for solutions to test without mocks I've found out about the functional core, imperative shell architecture. It sounds great, I also think that it would play nicely ...
 sentientbottleofwine's user avatar
2 votes
2 answers
163 views

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 ...
JF Meier's user avatar
  • 700
4 votes
4 answers
247 views

I am designing an analytics application using domain driven design and test driven development. I am having difficulty modeling the following requirement: The application shows a workitem's state. ...
Afelium's user avatar
  • 51
9 votes
10 answers
2k views

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, ...
Johan Thiborg-Ericson's user avatar
1 vote
5 answers
557 views

Say I have a bunch of classes that imitate cars: SportsCar, Truck, and SUV. All of these classes share some public methods like start() and stop() which they inherit from an abstract class Car. While ...
Ruben Rundström's user avatar
2 votes
4 answers
200 views

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 ...
Álvaro García's user avatar
4 votes
3 answers
868 views

My SUT class depends on external static state (which generally should be avoided, I know). How do I make sure my tests do not depend on their order of execution? I mean other by introducing some reset(...
Sergey Zolotarev's user avatar
0 votes
2 answers
241 views

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 ...
Mary's user avatar
  • 3
13 votes
10 answers
4k views

By QA testing I mean like say integration testing, system testing, regression testing, user acceptance testing and the like. If unit testing is skipped altogether would bugs that typically are spotted ...
Wes's user avatar
  • 335
0 votes
2 answers
232 views

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 ...
mguijarr's user avatar
  • 226
3 votes
2 answers
233 views

Say I have a method that expects data to be in some form to perform accurately. In the actual service/application flow, that data is formed upstream in other methods or services. How can I ensure the ...
Jason's user avatar
  • 33
2 votes
3 answers
461 views

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 ...
David Mason's user avatar
0 votes
6 answers
356 views

Lets say I have a class with two public methods and one private method. The private method is used by both public methods and unit tests that are written against either of the public methods, could ...
David Mason's user avatar
0 votes
4 answers
233 views

Lets say I have an API with two functions: CreateNewMachine(CreateMachineCommand createMachine); EditExistingMachine(EditMachineCommand editMachine); The internal logic of both functions should be ...
David Mason's user avatar
3 votes
3 answers
220 views

I've been tasked to use the Windows API (CreateProcessA, ExitProcess) to write a function that'll create, launch, and terminate some in-house applications (app1.exe, app2.exe). The two apps are fire-...
Minh Tran's user avatar
  • 163
1 vote
1 answer
176 views

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 ...
LNTR's user avatar
  • 43
2 votes
1 answer
514 views

I got assigned with writing unit tests for a class that instantiate a Worker inside in it's constructor. The code looks simmilar to this, class SomeClass { private _worker: Worker; constructor(...
LNTR's user avatar
  • 43
5 votes
5 answers
713 views

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 ...
Jagerber48's user avatar
0 votes
1 answer
180 views

I have multiple Flutter Android app projects that have different compatibilities of Java. Now, what should I do if I am developing more than one project simultaneously? If the first one uses Java 17, ...
DevQt's user avatar
  • 131
0 votes
2 answers
444 views

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 ...
Mike Nakis's user avatar
  • 32.8k
18 votes
10 answers
8k views

I've read many posts about unit tests only testing one object/class and mocking of objects should only be for direct dependencies of the object under tests. The only other option discussed for ...
Thor's user avatar
  • 307
12 votes
9 answers
8k views

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 ...
christian tiovanto's user avatar
0 votes
1 answer
560 views

I have a service method, acceptOrDenyJoinRequest, which follows a fairly complex flow (as depicted in this diagram): In my unit tests, the implementation details of this method are heavily reflected. ...
Saimur Rahman's user avatar
1 vote
1 answer
603 views

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 ...
Saimur Rahman's user avatar
0 votes
3 answers
483 views

I'm writing tests to check if validation rules are working for my CRUD app. I have constants defining stuff like max length of each String field. I'm unsure if within tests I should create test data ...
Domin0's user avatar
  • 111
1 vote
3 answers
486 views

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 ...
nicholaswmin's user avatar
  • 2,134
18 votes
11 answers
6k views

According to Why is Global State so Evil?, I know one of the disadvantages of "global state" is that it makes code "harder to test". I do not disagree with this, but what I don't ...
wcminipgasker2023's user avatar
2 votes
5 answers
498 views

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 ...
Jignesh M. Khatri's user avatar
0 votes
4 answers
335 views

Let's say that I've been iterating over my feature A with TDD. After several red-green-refactor cycles, I ended up with a nicely polished implementation with a part of the SUT encapsulated into some ...
Maciek Czarnik's user avatar
4 votes
8 answers
3k views

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 ...
imcoding's user avatar
0 votes
3 answers
289 views

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 ...
Diego Perez's user avatar
3 votes
2 answers
687 views

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 ...
Diego Perez's user avatar
2 votes
2 answers
425 views

Disclaimer: I am learning unit testing. I am also kind of beginner in object-oriented design. Currently, I am involved in the development of an application to manage the finance of a humble food ...
Siva Sankaran's user avatar
2 votes
1 answer
784 views

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 ...
Vladimir's user avatar
2 votes
3 answers
270 views

A little background on the project: we as a company receive a spaghetti source code, and into that we add even more spaghetti code. So with that I want to say that complete restructuring and ...
Tomáš Viks Pilný's user avatar
1 vote
3 answers
826 views

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 ...
CrystalBlue's user avatar
3 votes
3 answers
1k views

Suppose I had some Manager class that I need to change in regards to existing functionality by removing code. The Manager always sends an initial message after a connection was established to do an ...
Late347's user avatar
  • 55
3 votes
1 answer
276 views

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 ...
user19037628's user avatar
1 vote
1 answer
218 views

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 ...
Veverke's user avatar
  • 541
-3 votes
1 answer
112 views

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 ...
Wilko van der Veen's user avatar
2 votes
2 answers
240 views

There‘s an approach in unit testing where, instead of just writing the technical details in every test method, you create a library of helper functions like givenServiceFails (that acts on mock ...
nepa's user avatar
  • 304
4 votes
5 answers
414 views

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 ...
gaazkam's user avatar
  • 4,529
38 votes
12 answers
8k views

We all know the standard TDD cycle: I first write a unit test, the smallest unit test that fails; then I write some production code, again the smallest amount of production code that is sufficient to ...
gaazkam's user avatar
  • 4,529
0 votes
1 answer
114 views

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 ...
Valmir Cinquini's user avatar
0 votes
3 answers
471 views

We have a piece of code that decorates an interface to transparently add retry logic. Inversion of Control configuration service.AddOurRestApiClient() .AddResilienceHandler("Retry", ...
LostInComputer's user avatar

1
2 3 4 5
37