Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
3answers
38 views

Why is unit testing private methods considered as bad practice?

Context: I am currently working on a small project in Python. I commonly structure my classes with some public methods that are documented but mainly deal with the high level concepts (what a user of ...
1
vote
2answers
110 views

Is it good design to provide interfaces in a library that would only be used for unit testing?

Contrapositive-ish question: What is the design reason a library class would not implement an interface as a convenience to the developer? (e.g. the .Net library class FileInfo) The FileInfo class ...
3
votes
1answer
46 views

REPL-based Workflow and Unit Testing

As a developer who has primarily been doing functional programming in F# for the last several years, I'm very attached to my REPL and use it run my code as I go, testing and refining each function as ...
1
vote
3answers
242 views

Are unit tests needed for a function that only calls another function?

Assuming OldModule.oldFunc, if we want to move oldFunc to NewModule and, for backward compatibility, keep oldFunc there merely calling NewModule.newFunc by passing the exact same arguments and doing ...
0
votes
1answer
23 views

MVP Passive View -> Dependency Injection -> Factory Pattern -> Is testing behaviour whilst ignoring state enough?

I am writing an application using the Model/View/Presenter passive view pattern. I have view that contains multiple items in a list. My model is of type AudioDrama. For filtering that list I have ...
119
votes
15answers
18k views

How do you write unit tests for code with difficult to predict results?

I frequently work with very numeric / mathematical programs, where the exact result of a function is difficult to predict in advance. In trying to apply TDD with this kind of code, I often find ...
-1
votes
1answer
90 views

Unit Tests are duplicating the business logic

I have public class SomeDomainService { public SomeDomainService(IDependency1 someDependency1, IDependency2 someDependency2) { // ... } public void TestableMethod(int ...
7
votes
4answers
583 views

Should I test a method that calls a method that is already tested?

I have a method that does something like this public void addFunds(Account account, int price) { int credits = account.getCredits() account.setCredits(credits + price) saveOrUpdate(account) }...
0
votes
2answers
135 views

Unit Test a CRUD Controller MVC

I have looked through answers related to this but they don't seem to solve my problem. I am fairly new unit testing and testing as a whole. I just finished a small web application using ASP.NET Core ...
-3
votes
2answers
125 views

Is there such thing as minimum testing required when building a software?

As far as I know, ideally testing should be done extensively as hard and far as possible, however sometimes (always) we are required to ship quickly. In case of a delayed or a over-deadline projects, ...
4
votes
2answers
419 views

Should I be unit testing during prototyping/preparing for beta?

I am developing a web application for an industry that desperately needs it. Working with a consultant in the industry, I’ve rapidly developed a prototype in 2 months that we will be testing with a ...
1
vote
2answers
165 views

Is there any diagram for unit-tests?

I'm writing a software library for some numerical computations. I'd like to use Boost Unit Test framework to write a hierarchical unit-test covering not only basic input/output behavior of functions ...
0
votes
0answers
38 views

Unit testing multiple values [duplicate]

If I create a function to calculate the square root of a number, I suppose i should write a single unit test (maybe two, to test how it handles negative numbers). But what if I have a function which ...
3
votes
4answers
219 views

Should outgoing messages from object under test be tested?

I was watching a recording of a conference by Sandi Metz on testing. One of the things that I struggled with was that she said not to test outputs of the object under test (her example was query ...
0
votes
0answers
32 views

Calling other methods in unit test [duplicate]

I was learning about test driven development and came across unit testing. I have few questions regarding testing a class containing several methods; assuming i consider each of these methods a unit ...
1
vote
1answer
83 views

A performant and robust way to reset multiple files to its original state (TDD)

In our automated Java tests, we sometimes encounter issues, such as: Test A creates a custom file A.sh, that is then added on classpath Automated testsuite cleanup does not know about random file A....
2
votes
3answers
313 views

How far should I go with dependency injection and mocking?

Say I have a following class: public class A { public void execute() { if (something) ThirdPartyApi.method(); } } Now, I would like to test in particular the execute() method. I ...
2
votes
1answer
162 views

Handling hardware dependency while unit testing

I am writing a driver for an IMU sensor using test driven development approach. Communication protocol of choice is SPI. Using CubeMX and STM32F415 processor, SPI interface is implemented in ...
4
votes
5answers
487 views

Newbie question: Should all class public methods come from an interface?

I'm currently learning about TDD techniques, one of the suggestion is to test only public methods and skip the private ones. I have also been reading about Mocking. If I want to mock a certain method, ...
1
vote
4answers
227 views

Unit testing Markov chain code

What are the best ways to unit test code that outputs random sequences satisfying specific conditions, such as Markov chains? Let's be specific. There are two natural things to test: That the ...
0
votes
1answer
80 views

How to run machine-specific tests during DevOps remote build

What are the generally accepted means of running tests that pass on the dev machine on the build server where they'll consistently fail due to missing dependencies? (In this case, a configuration file ...
4
votes
2answers
274 views

TDD for Graphics application

I have googled and read few articles about the TDD for UI. I am not very much clear about how to start the implementation of the Graphics Application using Test Driven Development or how to write unit ...
2
votes
1answer
115 views

How to abstract HAL in embedded test driven development?

Recently I've been reading into topic of test driven development and decided to give it a go with a sensor driver I need. Sensor uses SPI interface and I will implement this driver on STM32F415 ...
0
votes
3answers
160 views

Can Aggregate Root Factory create the root, and it's internal classes?

Currently, my aggregates and value objects have protected constructors and some of them are being created by static factory methods inside the aggregate with descriptive names. It creates a nice DSL ...
2
votes
0answers
46 views

Where in your pipeline does a company that does X+ of deployments per day deal with running E2E/UA Tests [closed]

The ideal goal for my system is the ability to perform an arbitrary number of deployments per day to production while making sure each 'push' goes through the full test suite to make sure it holds up ...
9
votes
7answers
2k views

How to avoid the need to Unit test private methods

I know you're not supposed to test private methods, and if it looks like you need to, there might be a class in there waiting to come out. But, I don't want to have a gazillion classes just so that I ...
5
votes
4answers
200 views

Should I inject a Thread.sleeper as a dependency to make unit test easer?

I have a repeated pattern in my code that is not easy to test: classes that execute periodically. Just to simplify things lets say assume something like: while( running ){ long millisToWait = ...
5
votes
5answers
257 views

Tests independecy vs. architectural design

So, I'm doing a project that needs to consume a REST service. I'm using C#, and I'm writing implementation myself with HttpClient class. I also try to create some Unit Testing for my library, but that ...
1
vote
0answers
31 views

Integrating Testing with Model Checking

So with Model Checking you have a specification and the model checker automatically goes through your program's states and checks if it matches the specification. What I don't understand is where ...
6
votes
6answers
467 views

Is it bad practice to code the solution, then redo in TDD?

I might be wrong, but I feel like the best approach to TDD is Solution, Red, Green, Refactor (adding "Solution" to the standard formula). By coding the solution first, I feel like I am much more ...
0
votes
2answers
229 views

TDD with layered architecture, while only unit testing domain logic

Our project have a lot of layers, Entities Repositories UnitOfWorks Domain Services (Business Logic) Validation Infrastructure Application Services etc.. We are only writing unit tests for ...
-1
votes
1answer
95 views

What's the difference between “foo.spec.ts” and “foo.test.ts"?

When I use Angular CLI to generate a component, the test linked uses the logic foo.spec.ts. I am reading a tutorial where the test linked uses the logic foo.test.ts. What's the difference between “...
3
votes
5answers
599 views

If 100% test coverage is possible

In thinking about formal verification techniques, you also need to have test coverage. But as that article shows, you can easily say you have "100% test coverage", but every test doesn't have any ...
2
votes
2answers
180 views

In a codebase with all dependencies injected, can unit testing catch regressions?

Let's say I build my code so that I inject ALL dependencies to every class and when I test, I replace those dependencies with test doubles. Let's also say that when I work on a class I run its tests ...
1
vote
0answers
61 views

Automatic Test Case Generation

I enjoy writing unit tests when building software. Recently I have been learning about Model Checking to help show that a system matches a specification. Now I am returning to testing to see if it has ...
-3
votes
1answer
147 views

Unit Testing with multiple dependencies

Based on this Q: https://stackoverflow.com/questions/50968762/callback-not-being-called I understand (and its obvious in retrospect) what I'm doing wrong. However given the scenario as unit testing ...
0
votes
1answer
105 views

How to test controllers in a REST applications

I'm writing a REST api backend in NODE js, which is based on MVC approach. My api routes directly hit the controllers, which in turn import models which are a wrapper around the methods from a library ...
2
votes
3answers
222 views

Should I test the debug branch of my code in a unit test?

Lets say I have a function that gets a list of what files to send that are later send over a socket to some other pc. Now usually I keep track of what files have been sent and don't send these files ...
0
votes
1answer
81 views

How do I create an integration test that tests multiple microservices without mocking?

I understand the concept of mocking API responses and their uses in unit testing, but in functional/integration testing, I actually don't want to mock because that defeats the purpose. For example, ...
1
vote
6answers
395 views

How can I unit-test the presence of specific file contents, through an interface?

I am currently trying to test a file manager class. This class is responsible for keeping track of how long the file is good for. The file will have a date written into it that denotes when it was ...
0
votes
1answer
79 views

If I am mocking API responses in my unit/integration tests, how do I guarantee that the contract between Service A and B are valid?

Let's say I have microservice A and B. Microservice A calls microservice B for some piece of information. Microservice B requires parameters 1, 2, and 4 for the request to be valid. If I'm simply ...
1
vote
2answers
200 views

How do you unit test a microservice that makes a call to another microservice?

I have a suite of microservices: ConnectorRegistrar ConnectorTypeA ConnectorTypeB ... ConnectorTypeZ "Someone" can make a call to the ConnectorTypeA microservice to create a connector of type A, and ...
1
vote
4answers
199 views

Little value in unit-testing the database component

Having a component that represents the database is wonderful! You can use it from the business logic to read and write data. But should that component be unit-tested? I would argue that it should ...
1
vote
1answer
118 views

How to unit test high-level abstractions that transform complex Data

I'm practicing unit testing (specifically Test-driven design or Red-Green-Refactor) while writing a recursive descent parser for a simple domain-specific language. In trying to unit test a method that ...
1
vote
1answer
49 views

Keeping Stubs in Sync?

If I want to test frontend code (e.g. react SPA) that queries the backend and I stub out the responses from the backend using sinon fake server/fake XHR, then what happens if the backend code changes? ...
0
votes
3answers
152 views

Unit Testing method with multiple steps

I have a validation method like this def validate(a, b, c, d, e, f): Boolean = { val rs1 = check1(a, b) val rs2 = check2(c, d) val rs3 = check3(e, f) rs1 && rs2 && rs3 } I ...
0
votes
1answer
68 views

Client-Side TDD Tests?

More specifically, with regards to ATDD (sort of BDD flavored, or some could argue what was actually intended in the first place by TDD) should be there much UI testing? As I have been testing my UI ...
4
votes
4answers
371 views

What is the most concise way to test a boolean condition with many AND clauses?

I have a function which returns the availability of a module, where the module is only available if multiple conditions are all met. The code looks like this: bool isShipAvailable() { bool ...
8
votes
2answers
339 views

Philosophy on unit testing daisy-chained methods?

Problem Statement: I have a class that does some validation and it looks something like this: func a() {b()} func b() {c()} func c() {d()} func d() {e()} func e() {return} This is a simplified view,...
0
votes
0answers
22 views

How to unit test an SDL based frontend? Is it worth it? [duplicate]

I am currently beginning to create a small program/game in my free time and decided to try out SDL2 for my frontend/graphics code. I use the bindings from SDL2-CS, which is API-wise very close to the ...