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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

1
vote
1answer
68 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
208 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 ...
1
vote
1answer
117 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
432 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
191 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
78 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
236 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
83 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
97 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
43 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
191 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
244 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
27 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
430 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
147 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
58 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
520 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
175 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
58 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
128 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
96 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
217 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
77 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
276 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
64 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
146 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
193 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
92 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
44 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
138 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
62 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
320 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
329 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,...
-1
votes
1answer
97 views

Resource Reference key not found exception while unit testing

I have written a unit test for a converter. Converter - public class KvpOverrideLevelToColorConverter : IValueConverter { private const string redBrush = "redBrush"; private ...
0
votes
0answers
20 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 ...
1
vote
1answer
82 views

Testing Client-Side Code w/o Introducing Brittleness

I'm finding it tough to test my client-side code without testing implementation details. For example, lets say you are testing a login form that displays client-side validation errors and does not ...
-4
votes
2answers
128 views

How to unit test this converter?

I am beginning with unit testing in c#. Here is my converter: public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { int c = 0; if (value != null) {...
59
votes
8answers
11k views

Code coverage highlights unused methods - what should I do?

I have been tasked to increase code coverage of an existing Java project. I noticed that the code coverage tool (EclEmma) has highlighted some methods that are never called from anywhere. My initial ...
-2
votes
1answer
36 views

Is Python Doctest a White-Box or Black-Box technique

I have read many articles explaining the overview of black- and white-box testing, including this Stack Overflow question: https://stackoverflow.com/questions/7258524/unit-testing-black-box-testing-...
1
vote
4answers
227 views

How to prevent implementation/algorithm from leaking into unit tests?

I'm hesitating between algorithm and implementation as most of the questions here on how to prevent coupling between implementation and tests are about using spies/stubs or mocks. The typical problem ...
13
votes
4answers
813 views

How can you TDD for a bug that can only be tested after it has been fixed?

Here's one example: My web application contains draggable elements. When dragging an element, the browser produces a "ghost image". I want to remove the "ghost image" when dragging and I write a test ...
6
votes
2answers
187 views

What is the best practice of testing methods which call each other?

Say I have a method A which calls a method B and does one additional thing. The B method behaves differently in 10 different cases and I have a broad unit test describing it. And now I want to test my ...
87
votes
17answers
25k views

Why are unit tests failing seen as bad?

In some organisations, apparently, part of the software release process is to use unit testing, but at any point in time all unit tests must pass. Eg there might be some screen which shows all unit ...
5
votes
5answers
477 views

With TDD, tests obviously fail first.But is that really true?

I have been taught that with TDD, the tests "naturally fail first but it is a good habit to run them anyway to see the red light". Well, but I am quite sure a unit test written first for a new feature ...
1
vote
1answer
129 views

How to pass a mock object into a class for unit tests

There seem to be many ways to pass a mocked object into a class for unit testing and I am unsure which is the proper approach to take for my PHP application. If I was using Dependency Injection then ...
3
votes
4answers
123 views

What is the best practice for a regression test that wants to know about encapsulated information?

Suppose you have two classes: Alpha, and Bravo. Alpha constructs a new Bravo class during its own constructor and exposes no public visibility to it. Bravo has a String named charlie (and a method to ...
0
votes
1answer
55 views

Refactoring code which uses a global list and updates list based on messages from an external system

I am refactoring some code where a globally defined list is updated based on messages from an external system. Currently there is a global instance of the list. Various messages update the list ...
1
vote
4answers
221 views

Are parsers a special case in unit testing?

Context While trying to get my parser classes under test, I noticed a common challenge for (unit-)testing them: They have only one public method, with a string as input and the parsed class as output....
0
votes
1answer
29 views

Testing Application Helper that Depends on Controller

I am working on practicing TDD/BDD/ATDD and I am working on a rails application. I created a helper method that depends conditionally on the type of controller being tested. module ApplicationHelper ...