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
3answers
43 views

Finding Feature Bugs As Quickly As Possible

Currently, whenever I am developing a feature, I write the behaviour tests for it using mocks for our downstream services. These mocks are dumb always serve the same output. I faced something grave ...
0
votes
1answer
50 views

Is it bad practice to have a helper package in go for testing purposes. Or is this introducing dependence's

I find myself repeating the same code when writing unit tests, for example... When writing functions that work with files, In the setup for the test i often write some code to create a file (in a ...
2
votes
0answers
61 views

Is bad idea to utilize helper functions on integration tests?

In my job I have a small disagreement on whether we should utilize helper functions for making datasets especially in laravel framework. A sample for the test is: namespace Tests\MyAppTests; use ...
0
votes
1answer
78 views

An atomic method updates dozens of properties. Am I “testing too much”?

This question is about designing unit tests, something I started learning short ago. I know the principle that if you are testing too much in a single unitary test it is a smell, either of code or ...
6
votes
3answers
286 views

Should tests perform a single assertion, or are multiple related assertions acceptable

Assume a client is making a request to an API endpoint that returns a JSON response where the structure and data change depending on whether the request was successful or not. Possible responses may ...
0
votes
2answers
112 views

How to test business logic in isolation when it depends on input validation logic

Hello I am building a demo project to teach myself about clean architecture and unit testing. My setup is very similar to this github repo https://github.com/mmacneil/CleanAspNetCoreWebApi The ...
-3
votes
3answers
68 views

How to know if I need a unit test? [duplicate]

Do I need unit testing for everything? I know that Unit testing is not necessary for really small tasks, but what about for bigger stuff? How do I know I need a unit test?
9
votes
5answers
377 views

When do you have enough automatic testing to be confident in your continuous integration pipeline?

Continuous integration with testing is useful for making sure that you have "shippable" code checked in all the time. However, it is really difficult to keep up a comprehensive suite of tests and ...
0
votes
3answers
71 views

Unit Tests vs System Tests

I've always know Unit Tests to be something you do in code. You write functions to test other functions. Our team has been working with the same project manager for a while now and he's always ...
0
votes
1answer
93 views

Avoid too much dependencies for a Use Case in a Clean Architecture app

Context I'm currently developing an application following the Clean Architecture principles (at least I'm trying really hard to follow these). All my Dependency Injections are done manually, without ...
8
votes
4answers
798 views

How can I unit test methods which are using static methods?

Let's assume I wrote an extension method in C# for byte arrays which encodes them into hex strings, as follows: public static class Extensions { public static string ToHex(this byte[] binary) ...
8
votes
3answers
543 views

How do I write unit tests for legacy code (that I don't understand)?

Forward I've read a lot of things before asking this question, including many relevant questions right here on SE: (Software Engineering SE) Writing tests for code whose purpose I don't understand (...
28
votes
8answers
9k views

Methodology: Writing unit tests for another developer

I was thinking about software development and writing unit tests. I got following idea: Let's assume we have pairs of developers. Each pair is responsible for a part of the code. One from the pair ...
1
vote
4answers
289 views

Is it bad practice to repeat logic being tested in unit tests?

Often I find myself writing a unit test for code and repeating some or a lot of the logic in the unit test to make the unit test DRY. For example, consider the following piece of code: function ...
3
votes
2answers
337 views

Should one make the database calls in the constructor or method of a class?

Take the following instance for example: CreditCardApplication class public class CreditCardApplication { public int Id { get; set; } public string FirstName { get; set; } ...
0
votes
3answers
134 views

Does this unit test violate DAMP?

In writing a split function that breaks up a sentence into each individual word based upon punctuation i.e. splits on something like the character class [\s,.?!]+, though for the purposes of this ...
4
votes
2answers
214 views

How to test database dependent functionalities?

I have written this function which checks if a user already exists in the application: async function ValidateUserExists(username, email){ if(!username || !email) throw new Error('Invalid number ...
0
votes
1answer
140 views

Do I need to unit test a generic method with all accepted types?

For a method whose signature looks like this: public T Add<T>(T first, T second) where T : struct, IEquatable<T>, IComparable<T> which can work with all of the integral types, do I ...
3
votes
4answers
508 views

Should test code be treated as normal code? [duplicate]

I remember reading on someone else's post that test code should not be treated as normal code but as small whole programs and that is an idea I really like and would like to refer to when discussing ...
0
votes
1answer
95 views

Testing Stored procedure correctness

Suppose you have 2 stored procedure, let's say a GetProducts and a GetProductDetails. Now, the GetProducts returns a list of products with a property that is "calculated" basing on additional ...
2
votes
3answers
473 views

How to test required but accidental functionality?

For example, let's say I write a container class, which supports 2 kinds of operations: insert(x): inserts an element get_all(): retrieves all previously inserted elements Maybe it has some kind of ...
-2
votes
1answer
149 views

Unit tests branch best practices [closed]

I'd like advice about on the best practice for Pull Requests organizing on middle size project. Especially relating to Unit Testing. Currently we create branch for each feature, what is practically ...
-1
votes
2answers
95 views

Is testing UI components considered to be unit testing? [closed]

My UI components are tightly coupled with my UI framework (i.e. Vue + Vuetify). The framework provides some testing utilities that allow you to fake the rendering of these components without the need ...
0
votes
2answers
64 views

What to test when testing an API? [closed]

When testing an API (with, for example, Java), what parts should I actually be testing when calling methods of my Controller class (e.g. a Spring RestController)? For example, lets say I've got a ...
0
votes
2answers
95 views

Are refactorings expected to change unit tests that cover the functionality that is being refactored?

Imagine that you are using a tool that automatically applies a set of refactorings of your choice. If the refactorings breaks the existing API for whatever reason (e.g. change method name, ...
-2
votes
1answer
39 views

Documenting business logics of legacy application having no unit test

I have joined a team in company and this team owns few services, which are used widely by many other user facing internal/external UI apps and other internal apis. My manager gave me rough idea that ...
0
votes
1answer
67 views

Writing assertion for unit testing queue data structure

I have data structure queue with 2 operations: typedef struct queue queue void enqueue(queue *q, void *elem); void *dequeue(queue *q); queue *read_from_file(const char *path); I want to write ...
1
vote
2answers
66 views

Unit tests: tree of dependent tests

I frequently encounter situation where I have very basic tests, and if those fail, it doesn't make sense to run many other tests. Therefore I want to declare a tree of dependencies between my tests, ...
1
vote
2answers
60 views

Balancing function call overhead and testability in a code that is a part of the deep learning model training loop

I am currently implementing the transformer architecture for sequence to sequence problems. Key part of the model is the attention mechanism, which is basically a matrix multiplication, followed by a ...
0
votes
0answers
16 views

Should I do migration testing if the new library needs a different testing suite?

I'm using a pretty old library to make server requests which is not properly tested and it not really matching nowadays requirements, so the plan is to migrate to a new one over the next release. So ...
3
votes
4answers
174 views

Are there advantages to testing accessors separately?

If I were to have a class with a property on it should I be testing the get and set functionalities separately or together? class MyObject { public string Name { get; set; } } [TestClass] class ...
-2
votes
2answers
119 views

Which code to unit-test? [closed]

It is widely accepted, that UT's are necessary for any large project with automated testing. However, it is rarely the case, that 100% of the production code is covered by UT's. There are of course, ...
-2
votes
1answer
227 views

Mock db out or not during testing?

I am writing an app that mainly consists of just creating, editing and reading records in database. I was persuaded that any app has to be covered with tests. I was told that it's a good practice to ...
-2
votes
4answers
414 views

Mocking dbContext vs Repository [closed]

I use entity framework with Repository Pattern. while searching for means of writing unit test cases that run isolated from the database I found some people mocking the database context and others ...
1
vote
4answers
107 views

Unit Testing order with contained & inherited objects

I'm confused about unit testing order. Many posts in StackOverflow say that unit test should be independent and small. IMHO, in the case of aggregation or composition, the member objects should be ...
2
votes
3answers
153 views

Is it ok to write asserts on objects returned by a factory when the factory is the system under test?

I have code that follows this pattern. Class Factory build: returns: Add|Remove|Stub takes: property1, property2, property3 Class Add execute: does something takes: ...
0
votes
3answers
222 views

Unit test input values - validate or not?

I am manually creating a rather large data model as input to my unit tests. Data model is created using a number of builders. Developers use these builders in order to create the data model as they ...
0
votes
2answers
167 views

How to avoid ad hoc constructor for unit testing

According to the answer in this post Should my classes have separate constructors just for unit testing? ad hoc constructor is not good and should be avoided. Unfortunately, I have the same problem ...
1
vote
2answers
103 views

How to write unit tests a method with a result that is highly based on another method [duplicate]

How to write unit tests a method with a result that is highly based on another method ? async function getStatus( session, correlationId, data ) { const client = new SomeAPIWrapperClient({ ...
2
votes
1answer
71 views

Best practices on testing a function based on third party service

I'm trying to figure out how to create unit tests for a function, which behavior is based on a third party service. Suppose a function like this: def sync_check(): delta_secs = 90 now = ...
3
votes
1answer
124 views

How can the `log` function be used for formal verification

In JavaScript I want to create a log function: function log(string) { console.log(string) } Obviously this causes side effects; it prints to the screen. And I have no control over its ...
1
vote
1answer
64 views

Spring Boot Controller Unit Test Strategy

All of the controllers in our project are as dumb as we can make them. Rightfully so, they simply validate the incoming payload, hand the request over to a service layer, and return whatever response ...
4
votes
3answers
170 views

Is checking for unexpected types in dynamic languages in an untyped project necessary?

In statically typed languages or dynamically typed languages that use a type checking system you can guarantee that the input type is the type that you specified in the contract. However, in ...
-1
votes
1answer
81 views

Is there a best practice for storing certificates (e.g. x509), which include private keys, used in unit tests?

In a software library, I wrote, large parts of the code use x509 certificates for various puprposes like signing documents digitally. Is there a best practice for storing test certificates used for ...
-4
votes
1answer
368 views

What should I test with unit tests for data access layer? (MongoDB)

I'm working in TDD for my data access layer in MongoDB and I don't know what should I test? I think that I shouldn't test if the queries return what they have to return because It's a MongoDB concern....
4
votes
5answers
386 views

Should I Have One Interface Per Class For Unit Testing?

Should I define an interface for every public behavior class (excluding data classes)? I've spent many hours searching and reading to find a clear answer. If I search "Do you define an interface for ...
0
votes
1answer
89 views

Unit/Component testing using In Memory DB

I am writing Unit/Component test using In Memory DB. When I write Unit/Component test, I came across with the following question. I have the following two BL methods. ToCreate ToGet So when I ...
1
vote
1answer
650 views

Unit testing abstract classes with Google mock (gmock/gtest) (C++)

I want to test an abstract class with: Pure virtual methods that should be overridden in sub-classes Non-pure virtual methods that use the pure virtual methods (as opposed to this question) class Fu ...
1
vote
0answers
457 views

Unit testing C++ in XCode

I'm working on a plugin for some drafting software. The plugin takes the form of a dynamically loaded mach-o bundle. The software vendor provides a template plugin in the form of an XCode project. ...
0
votes
3answers
251 views

xUnit Should I Test Method Internal Work Or Only Result?

Let's take this unit test. Unit testing guidelines state that I should only have 1 assert per test, unless I'm testing the state of an object. In this case, Muxer.Muxe is a wrapper around FFMPEG that ...