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
2
votes
1answer
78 views

What do you unit test in your angular applications?

I am currently working in a team, which, when I joined them did not do any sort of unit or integration testing. Over the last 2 years I have bit by bit pushed dotnet unit testing to a point where it ...
5
votes
2answers
323 views

Is it a bad practice for a unit test to “trust” the other?

Assume I have the following two functions: function storeObject(object) { // Connect to database // Prepare query // Execute query } function retrieveObjectWith(id) { // Connect to ...
-2
votes
1answer
56 views

Testing function that return objects

My web app is built around classes that I call widgets. Their goal is to be reusable and modular, to suit different scenarios. For example, I have a widget called BreadcrumbWidget which has two ...
-4
votes
0answers
48 views

What is the right design pattern for me to abstract this class?

I am working with some code that takes advantage of ControllerContext. See: https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controllercontext?view=aspnet-mvc-5.2 My code looks something ...
0
votes
0answers
32 views

Unit testing an inductive problem? [duplicate]

I am developing a function that produces an inherently inductive output (calculating periods based on a start and end date). E.g., period n depends on the calculation on period n-1 and so forth. ...
-5
votes
0answers
26 views

Should test case naming rely on human readable sentence or concrete value?

There are many naming conventions for test cases. So I'll assume that I use GIVEN WHEN THEN. Question is should I name test cases based on a normal like so. GIVEN class with 3 students WHEN teacher ...
-1
votes
1answer
79 views

How to do test-driven front end development?

I'm trying to rapidly develop my frontend, but every time I change my code I find myself refreshing my browser and running some macro to test whether the changes in my code solved the problem. I ...
-1
votes
1answer
153 views

fake filesystem for unit tests

I am writing an application in c++ and Qt5. It would be very convenient for me to create a virtual file system so I can unit test code working on files. I have found that in Qt4 there was a ...
1
vote
3answers
167 views

How does TDD behave when the tested unit needs to be expanded?

I want to write some invoicing logic, and I start coding it, using TDD. The following example is silly, but I'm confident it represents well the everyday dilemma I'm facing function ...
0
votes
0answers
21 views

Is it ok to have a mix of PubSub and Request/Reply in a WebSocket server (focus on unit-test)?

I'm using Node.JS to build a system where the data get consumed by WebSocket requests, instead of classical REST API calls. WebSockets were used for realtime bidirectional communication, but then were ...
1
vote
1answer
107 views

C# | How to Unit test a Timer (in a daily job run scheduler)?

I wrote this class: using System; using System.Threading; using System.Threading.Tasks; public interface IJobScheduler { void RunDaily(Task task, int hour, int minutes ); } ...
-1
votes
2answers
64 views

Code Review for Automated Unit Tests [duplicate]

Writing automated unit tests is followed as a part of our development process. We also do have an established code review process for the development code that is written. Should the test code be ...
0
votes
2answers
90 views

What approach do I take to unit testing a class which has a method that internally calls other methods?

I have a class which has one method that is called from another class. This method internally calls several other methods to do its work. Those other methods are all public and can be called by the ...
0
votes
3answers
121 views

Is it good practice to create a facade only to be able to mock the wrapped implementation?

I'm currently writing unit tests for ASP.NET Core Controllers. Some controllers inject UserManager<T> which seems to be a really hard type to mock. After some attempts to mock or even fake it, I ...
-1
votes
1answer
88 views

Won't a characterization/regression test fail when a bug is fixed?

Let's assume that you are trying to refactor a legacy code to make it easier to understand and more testable, how can you do that? In the book "Working with Legacy Code", a characterization/...
-2
votes
2answers
123 views

Is it possible to write unit tests for embedded systems with no prior embedded programming knowledge?

I have this question for a long time that is it possible for someone with no prior embedded systems programming experience to write unit tests? I have good knowledge of other languages like JAVA, ...
5
votes
3answers
444 views

How Should I Unit Test A Data Transfer Object?

Consider the following sample C# Data Transfer Object (DTO): public class MailingAddress { public string StreetAddress {get; set;} public string City {get; set;} public string ...
-3
votes
1answer
168 views

What are the best practices for writing a long, multi-step process? [closed]

When writing a long process, i.e. one filled with many steps of business logic, what are the best practices for organising it? There are a few different options here that I can see: Just write a long ...
4
votes
3answers
248 views

Testing unexpected inputs for unit tests and loops?

I'm working on an enterprise that has some Angular/Typescript projects and to avoid repeating code (basically copying and pasting) between them, we decided to go for Monorepo and start write an util ...
-3
votes
2answers
57 views

Layer to mock in tests: database or higher?

Suppose there are 2 layers below the layer being tested: Technical Logic Layer: calls the DAO layer. DAO layer: calls the database (The layer being tested can call the Technical Logic Layer but ...
-4
votes
3answers
99 views

What can an assertion test that running the actual code cannot?

I'm currently learning Jest, Enzyme, Detox and testing in general, but I'm still trying to grasp the benefit of testing. From what I understand, testing is about creating hypothetical situations. Let'...
-4
votes
1answer
79 views

Why do we have to copy all files into dedicated folder when doing unit tests?

I'm using Mocha Library and the Library by default use a Test folder. So, I have to copy the code I written in production into Test folder when doing Unit Tests with Mocha. Anyone can think reason ...
0
votes
3answers
103 views

Unit Testing: Constructor Injection with Fake Objects - Bad Tests?

In The Art of Unit Testing, 2nd Ed., the author gives the following example for injecting a stub using constructor injection and a "fake object". The goal of the "fake object" is to inherit the ...
0
votes
2answers
96 views

Should I refactor this class to use a Factory?

Given the following class in a Legacy code base without any UT's. So any refactoring done should be done on the smallest possible scale, just in order to be able to write UT's. public class Person { ...
1
vote
2answers
138 views

Are in-memory database a form of integration tests?

I have looked through most of the answers given regarding using in-memory database for unit test, but I could not find one that was clear to me. I am writing some unit tests to cover some of our ...
1
vote
5answers
68 views

DDD does this (database)logic belong in the model

I'm trying to figure out where to put business logic and why and where performance fits in. Im trying to get away from the fat logic-filled repositories that we produce a lot in my company. So i'm ...
0
votes
1answer
87 views

Entity Framework and Domain Driven Design Testability

I'm using a DDD approach for the Domain classes. Although, I have a problem on my design, that I'm handling it now but didn't have a good idea to over tackle it. My Architecture is the follow one: - ...
2
votes
1answer
97 views

Wrapping a legacy project in a test framework

I am working on wrapping an old project written in C# in a test framework. The largest problem I have is that I have a bunch of classes that are all VERY tightly coupled with other classes. All of ...
-4
votes
1answer
40 views

Unit testing data-transformation functions that call external APIs

Lets say you have a class that has the responsibility producing a set of finished data, but the method of producing that data is intentionally an implementation detail and as such should be left ...
-2
votes
1answer
60 views

pep8 (D103) I need docstrings for my unit test functions too?

Perhaps im not defining my pytests right but im seeing this: Does pep8 demand a docstring for each unit test function too? I cant find pep8 docs specific to this, wondering if pep8/flake8 is unit ...
1
vote
1answer
119 views

Unit testing an existing project by creating interfaces for all public classes (including GUI forms)

This is an existing C# .NET WinForms project. I assume it was not developed with unit tests in mind from the very beginning. It uses a Model-View-Controller architecture, and the backend is a content ...
7
votes
2answers
272 views

Should examples for functions be unit tests?

I'm writing a python function to replace all the non-alphanumeric characters in the keys of this dictionary with underscores. To make sure it's working as expected as I don't have a ton of ...
0
votes
0answers
31 views

Shared stub or “private” stub for other modules in testing?

A methodology question again... Say we have an article module, a feed module, and a user module. We encapsulate them, so the user module only exposes one method User getUserById(int id) (all others ...
1
vote
2answers
81 views

Is “one representative” enough or need to have many same-type things in testing?

This is (again) a question of methodology... Suppose we are testing a service that returns Articles given ids, i.e. List<Article> getArticles(List<Integer> ids);. In addition, the ...
33
votes
9answers
6k views

Testing the wording of an Exception message

Doing a code review, I ran into this assertion in a unit test: assertThatThrownBy(() -> shoppingCartService.payForCart(command)) .isInstanceOfSatisfying(PaymentException.class, exception -&...
2
votes
1answer
152 views

Why should I write unit test for my example instead of (or with) my integration test

I have a repository function on my repository layer. I use sequelize as data access. I will write tests for my function. Here is the logic I want in English: My function should save a user to ...
4
votes
5answers
604 views

Is it a good practice to include “magic numbers” in test case name?

Imagine a twitter-like app where users are allowed to follow to a limited amount of users; say 100. I have this code: fun follow(followerId: String, followedId: String) { if (repo.countFollowing(...
-1
votes
1answer
66 views

How can I efficiently test that a parser handles multiple levels of operator precedence correctly?

I'm working on a parser for a (very small) toy language, and I want to test that it's parsing expressions with the appropriate precedence. Previously I just had arithmetic operators, so there weren't ...
1
vote
1answer
116 views

In C++, how would one unit test a method that must throw an exception when a private array no longer has “space”?

I am implementing an ECS system with a data-oriented design, and with a TDD methodology using Catch 2. I have the following class declaration snippet for an EntityManager: using Entity = std::...
0
votes
0answers
43 views

Logically equivalent conditionals, same test, but different condition coverage (google test)

Title pretty much says it. I ran into trouble getting condition coverage of a logical statement and found that the order in which the statement is written (rather than order of operations) results in ...
0
votes
3answers
292 views

Is this proper way to unit test?

I'm trying to unit test some repositories and have no idea what I'm doing if someone could point in the right direction that would be good, currently, I'm testing behaviour of creating a new user ...
-3
votes
4answers
360 views

How to break the vicious cycle of test-writing preceding an initial release?

I'm developing a FOSS library which I am pretty fond of. More specific details probably don't matter. I've already "finished" a feature set sufficient for an initial release IMHO. However - some of ...
0
votes
1answer
64 views

Which of these is a better practice to write Python unittest for CRUD operations of REST api?

I have a python class that has methods to perform the CRUD operations via REST api: class my_class(): def get_obj(self,...) -> requests.Response: res = requests.get(...); ...
0
votes
1answer
24 views

Non regression test for small set of data data driven from database, how to handle future data

While writing this question I found out that I'm faced with 2 problems: a testing one and a production one but I hope that resolving the situation can solve both issues. Now the question: I have a ...
1
vote
4answers
173 views

Black-box testing when testing without mocking?

My understanding of mocking vs not mocking is that mocking too much creates brittle tests that need to be changed all the time, while on the other hand less mocking better verifies that the system ...
1
vote
1answer
66 views

Can you call functions that are not being tested as part of the unit test?

So I've got "Services" in my system that handle creating, updating etc of the data. For example state_service.create() would create a new state in the database. This state belongs to a group. The ...
-1
votes
1answer
116 views

Determination of pass/fail for unit testing?

Would it be fair to say that almost all unit test frameworks use assertions, or a single assertion, to determine whether or not a test has passed or failed? In particular, are there any frameworks ...
4
votes
2answers
212 views

Unit tests vs Automation testing

I'm a C# developer & never worked before on either unit tests or Selenium browser test automation. For a current assignment, there is an existing Visual Studio solution that has a project that ...
2
votes
1answer
104 views

How to follow execution path of a Unit Test in real time without manually stepping through the code line-by-line?

I'm using MSTest. I have some async functions I'm unit testing that rely upon a lot of different methods where the result needs to be awaited upon. Sometimes the unit tests stall in a "running" stage ...
0
votes
1answer
47 views

If you use Spring dependency injection does the unit test require some Spring stuff?

I completely understand, I think, how injecting a dependency of a class allows that dependency to be mocked and the class to be tested with the mocked version. What I am not sure about is if you use @...

1
2 3 4 5
31