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
57 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
-4 votes
0 answers
73 views

Which one of these descriptions better describes a correct unit testing? [closed]

EDIT: My question is purely about definition and meaning of term "unit testing". Across different projects, I've seen a 2 different "schools" of writing unit tests. Which one is ...
Gieted's user avatar
  • 93
1 vote
4 answers
748 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. ...
Yashoja Lakmith's user avatar
2 votes
2 answers
292 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 ...
Brian Smooner's 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
74 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
408 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
483 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
51 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,691
1 vote
2 answers
187 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
72 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
136 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
256 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
248 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
354 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
118 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
466 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
182 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
122 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
168 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
227 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
  • 195
1 vote
3 answers
290 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
675 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
202 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
14k 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
2 votes
2 answers
261 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
314 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
114 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
423 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
377 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,007
0 votes
2 answers
257 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
221 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
801 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 votes
1 answer
81 views

Efficient way to write test cases depending on a Micro service

I'm very new to microservice architecture. In the Monolithic app structure, it was pretty straightforward to write test cases since everything was in one app. I have a situation where I manage a ...
Koushik Das's user avatar
7 votes
5 answers
699 views

How to initiate unit testing when you're the grunt?

I am the newest programmer on a very small team of 6 developers, 3 of which are offsite. By "newest" I mean both in years of experience (drastically) and familiarity with the code. I've been ...
tageta72's user avatar
  • 181
2 votes
3 answers
245 views

Method that returns an object is it adequate for TDD?

Let's suppose I want to follow TDD (Test driven development) and I want to implement a class that is supposed to return a considerable object. It starts to get really complex in my opinion and doesn't ...
Nmaster88's user avatar
  • 167
20 votes
8 answers
7k views

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 ...
BAmadeusJ's user avatar
  • 326
0 votes
1 answer
512 views

Should I use my View Model to Test my Views in SwiftUI?

I was reading a post about testing in SwiftUI and the author said that don't write unit tests for your View Models that tests the UI of your view. The example he gave was a simple counter app. ...
john doe's user avatar
  • 141
2 votes
2 answers
514 views

Where do unit tests stop and integration tests begin according to the classical school of unit testing?

There are two schools of thought on how unit tests should be written. The first is the Classical/Chicago school, which focuses on the isolation of unit tests, describes a unit as a class or set of ...
B-Rad's user avatar
  • 203
4 votes
2 answers
443 views

How to write maintainable unit tests using classical style of unit testing

When I am using the classical style of unit testing, how do I keep the number of test cases for an object that has many collaborators from growing too large? And how do I keep the setup of each test ...
dbird's user avatar
  • 159
0 votes
0 answers
65 views

Unit testing with dependency on Word COM objects: Wrappers & interfaces vs document as an embedded resource

We are developing Word Addins that interact with elements in Word documents. To make it testable, my approach has been to use interfaces and wrappers for UI elements, and then provide mock alternative ...
Peter Dongan's user avatar
0 votes
4 answers
404 views

Dependency injection in legacy code

I have a legacy project with many classes with high coupling, and I have a necessity to test some of them. So, I decided to introduce dependency injection principle but stumbled upon where to create ...
Ruslan's user avatar
  • 9
2 votes
3 answers
213 views

Unit Testing Internal Classes

Advice on unit testing is often focused on publicly exposed classes. What about cases where the only public class is simply there to instantiate internal classes? Should the internal classes be unit ...
user12994244's user avatar
0 votes
1 answer
87 views

Do we need to test an integration of units if each unit has been tested against collaborator (mocks) and interface contracts?

Given: Let's say I have 3 objects A, B, C that form a cluster. Each unit (A,B,C) is independently tested with mocked collaborators. The "integration" is the call to A that calls out to B and ...
PhD's user avatar
  • 2,531
0 votes
2 answers
164 views

Testing an assertion across all test cases

I have recently developed a small module that performs queries against a database. At the end of each test that contains code performing modifying queries against the database, I added an assert that ...
krezno's user avatar
  • 167
0 votes
5 answers
750 views

Unit Testing - should / how should I write tests to cover new code that doesn't affect the interface of a method?

Having been trying to improve my unit tests, I'm trying to adhere to the principle of avoiding call verification. This is because it aligns with other principles I believe to be true: We Should test ...
gbro3n's user avatar
  • 491
0 votes
2 answers
205 views

Unit testing 'opaque' classes / structs

I'm sorry, no good title. I'm working on a C project right now and am writing tests. I usually do a 'struct method' style of programming. So I have opaque structs (no implementation revealed outside ...
Derek C.'s user avatar
  • 617
2 votes
1 answer
242 views

How to avoid class-proliferation when creating a unit-testable system?

I've been working on a personal project for some time, and I believe that I'm at that point where, if I don't embrace unit tests (and ideally TDD) now, it may be too late, so I want to make the right ...
Pablo's user avatar
  • 29

1
2 3 4 5
36