Skip to main content

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

In unit testing: How to abstract a dependency of subject under test?

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

How to decouple spagheti code for unit tests [duplicate]

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
-4 votes
1 answer
93 views

Refactoring the testing code inside a big switch code block

The main logic of my function is a switch case, with the default case being the abnormal case. function main(input) { let result = process(input) switch (result): { //normal cases case ...
Qiulang 邱朗's user avatar
1 vote
3 answers
155 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 ...
CrystalBlue's user avatar
3 votes
3 answers
1k views

TDD when removing long lived feature

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
1 vote
1 answer
105 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 ...
user19037628's user avatar
1 vote
1 answer
100 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 ...
Veverke's user avatar
  • 461
-3 votes
1 answer
87 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 ...
Wilko van der Veen's user avatar
2 votes
2 answers
186 views

How do we call the approach to unit test through an additional layer of abstraction? [closed]

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

How do unit tests facilitate refactoring without introducing regressions?

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,479
0 votes
1 answer
90 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 ...
Valmir Cinquini's user avatar
0 votes
3 answers
352 views

Would you test this piece of configuration code? How do I determine which code is worth testing?

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
0 votes
2 answers
84 views

EFCore In Memory repository Unit Test of Encrypted data

I have in project linq repository unit tests. [Fact] public async Task Get_FromTreeEntitiesUnsorted_RetunsOrderByDescending() { //Arrange _contextReadonly.Entity.Add(new ...
cargt4's user avatar
  • 19
1 vote
4 answers
1k views

Should the unit tests be independent of the implementations

In the book- The Art of Unit Testing, I have read that the changes to the code base should not change the unit tests. But I have a hard time figuring out what should not be changed in the unit tests. ...
Critical Failure- Core Dumped's user avatar
2 votes
2 answers
336 views

Unit testing for non-stateless units - how?

Firstly let me say I have never written a unit test in my life. I am trying to get the hang of PHPUnit, and so far it's working pretty well for me so far as "stateless" functions (that ...
user avatar
9 votes
3 answers
6k views

How should source code unit tests affect semantic versioning?

I recently started using Semantic Versioning. Due to conflicts with my previous versioning convention (which I created myself), I am very confused about versioning unit tests as part of the public API....
KhodeNima's user avatar
  • 225
2 votes
1 answer
86 views

What is the correct way to configure a testing mode on a class?

I have a repository which reads and writes to Firestore, and some tests to make sure data is sent and comes back in the correct way. In order to test this I added a protected function which returns ...
Adam's user avatar
  • 272
1 vote
3 answers
419 views

Is low code quality and lack of testing the norm in B2B software development?

I've been working at this company for about a year now. it's a growth company working in B2B. I'm one year out of university, with a major in computer science. I work in the web team, using an Angular ...
Jeremaia Scott's user avatar
0 votes
1 answer
914 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?
Akshunya's user avatar
  • 111
0 votes
0 answers
58 views

Is using @Transactional together with @Test annotation on the same test method a good practice?

In my current Java project, there is such style of integration test: @Test @Transactional public void testBusinessTransaction() throws Exception { //...complicate set up code and execution code ...
Rui's user avatar
  • 1,865
1 vote
2 answers
196 views

Is it possible to prove mathematically that unit testing reduces test effort as compared to integration testing? [closed]

I took out the request for a paper, thank you for spending so much time on this. hopefully this edit is better. I use the word "complexity" meaning "cyclomatic complexity" so if ...
Mister Jeps's user avatar
1 vote
2 answers
74 views

Test-doubling a file path in Java/Groovy

I am trying to write a unit test for a helper method in my ApiRequestHandler which handles APIGatewayProxyRequestEvent . This class uses an EFS file path, which is where it writes files to. I have ...
Mike Warren's user avatar
-1 votes
1 answer
240 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, ...
oligofren's user avatar
  • 107
2 votes
3 answers
261 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 ...
Bimo Adityarahman's user avatar
2 votes
2 answers
339 views

Best practices for unit testing when breaking down functions into smaller ones

Say we have a function of the form def func(num: int) -> int: num = num + 1 num = 2 * num num = num**3 return num and let us act like each line is a long computation so that we ...
grebs's user avatar
  • 39
2 votes
3 answers
480 views

Should Acceptance Criteria be mapped to unit tests?

My organisation is adapting a new SDLC process, and a part of this is to force engineers to map acceptance criteria (AC) to unit tests written for each user story in the pull request (PR). To satisfy ...
Saket Kumar's user avatar
0 votes
0 answers
48 views

How do you decide what is worth writing a unit test for [duplicate]

In an app I'm working in there's a service class(among others) which is used just to call methods on other classes. Recently I've had to work in that area and add another method that does what all the ...
Andrei's user avatar
  • 109
1 vote
1 answer
132 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 ...
Derek's user avatar
  • 121
1 vote
4 answers
761 views

Is it worth unit testing hardcoded values? [closed]

I recently worked on a project where the team were writing lots of unit tests for hardcoded values, for example, unit tests that test the value of a string constant. The justification being that they ...
Darren Findlay's user avatar
2 votes
2 answers
203 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 ...
rklec's user avatar
  • 31
1 vote
2 answers
131 views

When writing automated tests for a website relying heavily on a template language, how do I gain confidence while maintaining fast feedback?

I'm working on a website that, for all intents and purposes, functions as a Choose Your Own Adventure book rendered as a single page app (SPA). Starting at the left, this is the user experience: Each ...
Daniel Kaplan's user avatar
1 vote
3 answers
171 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 ...
Dave Cousineau's user avatar
2 votes
3 answers
243 views

Should edge cases be part of one test, or each their own case?

I am writing tests TDD-style for a cryptography package containing encryption and decryption methods. I test my methods with various kinds of inputs, including multiline strings, mixed case, calling ...
Marvin's user avatar
  • 222
1 vote
3 answers
446 views

How do you test whether schema changes will break services?

I maintain a relational database of sorts, and occasionally a feature request requires a schema change (eg. add a new column, etc...). However, a number of "services" consume this data. It's ...
MYK's user avatar
  • 343
0 votes
4 answers
1k views

Testing for exception thrown, unit or integration test?

In a test, asserting if a simple method throws an exception under a certain circumstance, is such a test considered a unit or integration test when the exception object thrown is from the standard ...
Kid Diamond's user avatar
1 vote
3 answers
214 views

TDD - What to do when adding a new function on a dependency causes many previous tests to fail?

I was programming today and encountered something that just feels like I'm doing something wrong (maybe?). I've encountered this situation before, but I wanted to reach out and ask if there's a better ...
jrgilman's user avatar
  • 121
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 ...
Edwardo's user avatar
  • 947
3 votes
2 answers
380 views

Is it okay to use Dependency injection only because of unit testing?

I have a class that has dependencies that I know are not going to change. class ConversationFinder { public function __construct( protected Conversation $conversationDbFinder = new ...
Ghassan Barghouti's user avatar
2 votes
3 answers
318 views

Unit testing code which does not establish correlation between input and output

In most descriptions of unit testing as a methodology there's an idea of unit tests being as independent of implementation as possible. This is easy to understand and implement in cases when code does ...
Roman's user avatar
  • 139
9 votes
5 answers
4k views

Which comes first: CD/Trunk-based development or microservices?

My company* wants to move from using long-running feature branching (~up to a few weeks) to continuous integration with trunk-based development, and to break up our monolith into microservices. We'...
Jacob Archambault's user avatar
-1 votes
3 answers
115 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 ...
sergiol's user avatar
  • 157
2 votes
2 answers
496 views

Does the "Pyramid of tests" contradict the idea of tests focusing on behaviour?

I am talking about these two testing strategies : Have a pyramid of tests (with many more unit tests than high-level tests), because high level tests are harder to maintain and slower (see also : ...
Tristan's user avatar
  • 207
3 votes
7 answers
419 views

How can unit tests be atomic in server-dependent CRUD apps?

Suppose that the following are true: You believe that unit tests should be atomic. That is, tests should always test exactly one thing. You have written a CRUD app in a general-purpose language such ...
J. Mini's user avatar
  • 1,017
0 votes
2 answers
303 views

What is a good unit testing strategy against a chain of public method calls?

say I have this code which is a chain of public methods, public_c calls public_b calls public_a def public_a(...): ... def public_b(...): ... public_a(...) def public_c(...): ... ...
James Lin's user avatar
  • 199
0 votes
3 answers
238 views

Test driven reduction of technical debt

Suppose you have been put in charge of an already existing project. As you are starting to familiarize yourself with the repository, you notice a few technical debt issues (insufficient test coverage, ...
EdG's user avatar
  • 11
3 votes
3 answers
961 views

How to write effective automated tests when building GPT4 powered software?

Part of my current product uses GPT-4 with a prompt to extract information from plain text. As behaviour of large language models is inherently opaque and failure cases unpredictable, I was wondering ...
Armin's user avatar
  • 65

1
2 3 4 5
36