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
0answers
17 views

How to send a merge request for a new unit test that fails? [migrated]

I found a bug in a open source project. The bug is easy to reproduce and as such I have added a failing unit test (the project already uses unit tests) and submitted a pull request. I have not fixed ...
0
votes
1answer
55 views

Testing a message queue worker process?

Say you have an AWS SQS queue. Your Publisher class and Receiver class is already unit tested. Now you have a worker process that uses the Receiver class to actually receive the messages from SQS. My ...
0
votes
1answer
86 views

Does it make sense to write one unit test and loop it through similar components?

I have a situation where I have different forms, each with 4 or 5 steps (components), and I decided to write one unit test per step. After doing it, I noticed they were very similar and I could just ...
1
vote
2answers
137 views

Where should I start with an Integration Test for a Legacy Software in .NET? [closed]

Currently, I'm planning a new project of CI/CD with Azure DevOps (with Git, already committed) for an old Solution, which contains 17 C# projects. Technically, we have access to the source code and ...
0
votes
1answer
45 views

What's the best kind of test for complex calculations without access to external resources?

I have two libraries that handle the mapping from one family of objects to another one. I had to create a middle set of objects for other transformations. So, the NativeConverters libray converts ...
1
vote
1answer
51 views

Kotlin delegation, what should I test?

In Kotlin the powerful construct of delegation can be used to extend functionality of existing interfaces by reusing existing implementations. class Demo : Map by HashMap {} Questions: What should ...
2
votes
2answers
245 views

Does my class violate the Single Responsibility Principle in SOLID?

I want to ask: Whether the Role class violates Single Responsibility Principle in SOLID ? I think deleteAccount() is not belong to Role class but Role class is way to extend code in the future ...
23
votes
3answers
5k views

Struggling with cyclical dependencies in unit tests

I'm trying to practice TDD, by using it to develop a simple like Bit Vector. I happen to be using Swift, but this is a language-agnostic question. My BitVector is a struct that stores a single UInt64,...
1
vote
1answer
121 views

Unit testing as non developer [closed]

How possible is it for a non-dev, Qa person, to on board themselves to learn how to unit test production code? SI have an understanding of how code is written and understand basic logic but what do ...
0
votes
3answers
157 views

Is there a good reason not to use a unit test framework's Assert methods to throw exceptions in actual app code? [duplicate]

For instance, insteead of if (MyFancyObject is null) throw new InvalidOperationException(); I could simply say Assert.IsNotNull(MyFancyObject); But I hardly ever see this done - is there a ...
1
vote
3answers
192 views

How to write DRY Unit Tests when order of method calls matters

Suppose I'm writing a calculator engine with a class as follows... public class ArithmeticExpression { ArithmeticExpression Add(double operand) { /* ... */ } ArithmeticExpression Subtract(...
2
votes
3answers
373 views

TDD: Create a Game logic using Test-First Programming

I'm implementing a simple command line game using TDD principles and Unit Testing. My goal is to implement the whole game using Test-First Programming, so every behaviour/class is created from a test. ...
2
votes
4answers
211 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
68 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
89 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
84 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
348 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
119 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
71 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
429 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
81 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
101 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
841 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
565 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
301 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
365 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
137 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
222 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
144 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
512 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
479 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
168 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
109 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
66 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
97 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
43 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
70 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
67 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
65 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
177 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
286 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
680 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
117 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
154 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
273 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
182 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 ...