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
1
vote
1answer
106 views

Unit Testing against Detailed Design, How to perform requirements based tests ISO 29119? Traceability to Unit Requirements?

According to the standards like ISO 29119 & ASPICE, the left side of the V-Model contains Requirements, Architecture Design and Detailed Design. On the test side, there are Unit/Component Test, ...
0
votes
1answer
37 views

Unit testing async tcp server

I built an async multi-client TCP server for RPC usage. It's working well but I've found it difficult to unit test certain functionality: Connect 2x clients, is client count 2 Connect 1x ...
0
votes
2answers
56 views

Testing Environment Variables Strategies

I am in the process of implementing an API for the OPTIONS request for a pre-flight check on CORS calls. The Allowed-Origins host between local, test and prod will all be different so I moved this to ...
10
votes
2answers
280 views

Is it possible to test if/else trees properly without coding to the implementation?

I have been writing tests for a lot of long if/else trees recently, and I'm finding it a little discouraging. I want to speak in concrete terms, so consider the following example (I'll write in Ruby ...
-1
votes
2answers
97 views

Why don't people usually use asserts throughout their application?

I usually do Javascript and I like putting console.assert liberally in my application. It throws an error if the first argument is falsey. E.g.: console.assert(price > 0, 'Price isn\'t above 0') ...
2
votes
1answer
70 views

Testing Queries Themselves with Test data is a Unit test or an Integration test?

In a php project that I maintain I have a database structure without migrations, hence no way to reproduce it or make on the fly a test database. And the queries used to be performed on them are ...
1
vote
0answers
46 views

How to run the Unit Test on Master branch using hook before merging the incoming changes of other branches

We have project which have more than 500 unit test and run for hours through Jenkins CI pipeline. In case there is failure of single UNIT test we need to kick off the build job again. I want to run ...
2
votes
3answers
135 views

How to maintain XML/JSON serialization tests?

It is quite common to test JSON / XML producing methods against file-stored expected output (at least in Java world, but probably in other environments, too). For instance there's a method that ...
2
votes
5answers
336 views

Clean code vs ease of testing: Make method params explicit when they are class attributes just so unit testing is easier?

In Clean Code, we're advised to reduce, wherever possible, the number of arguments in a method's signature. This can often be achieved by using class attributes in lieu of parameters. Now in a code ...
2
votes
8answers
292 views

Should automated testing be specified in software requirements?

When defining software requirements, should automated testing (unit and integration) be specified? I have not seen any guidance on this, and "testing" is not a functional requirement for the software. ...
-2
votes
0answers
71 views

Should Redux.js actions/reducers/selectors be unit tested as a behavioral unit?

I have been delving more into BDD ever since struggling with my initial attempt at TDD and I am wondering how testing Redux reducers/selectors would fit into a good unit tested piece of software? ...
-2
votes
1answer
56 views

A Question regarding many testing criteria

We know that there exists many testing criterions . As an examples : 1) Statement criterion 2) Branching Criterion 3) Path Criterion. My questions are : 1) Where do we just use these measures I ...
0
votes
1answer
40 views

What architechture to follow when I need to make user login? Android

I am writing an app, some of its functionalities require the user to be authenticated. I am planning to create an annotation like this: @RequiresAuth fun commentOnTask(){ .... } this annotation ...
-3
votes
3answers
154 views

Is it worth it to only test the 'big picture', without having automated tests for edge cases?

After a period of time in my life when I was making it a point of my honor to reject all programming principles and patterns I finally came to the conclusion that I was indeed being arrogant and ...
3
votes
4answers
192 views

Should automatic tests interact with the outer world?

Interacting with an external server is a major part of the functionality of an app I have to write. I've always been told that automatic tests are not supposed to interact with the outside world. ...
1
vote
2answers
131 views

Unit Testing business logic layer that depends on data access layer [duplicate]

a discussion that rose among us devs: how to do unit test of Business logic layer that depends on data access layer. the two options are create test data in a test database (for example, H2). let the ...
1
vote
2answers
82 views

How to configure and setup an IOC Container for a library?

When using Dependency Injection across internal classes (implementation details) in a library which is to be consumed by multiple applications, is there a good way to configure the IOC container? ...
1
vote
3answers
243 views

In TDD, is it bad practice to write helper class for unit tests?

Sometimes when writing a unit test using Test Driven Development (TDD) one may find that checking if the result is the correct one is "more complicated than one line of code", probably deserving its ...
-1
votes
2answers
143 views

In TDD, should returning class of public method be unit tested independently?

Suppose that I have a class that is returned only as a byproduct of another "main" class. I am using a Test Driven Development (TDD) workflow. Should this byproduct class be unit tested independently ...
1
vote
1answer
105 views

Unit test compiled dll or shared code

I have code in a (Visual Studio) Shared Project, and a number of end solutions/projects which compile and build the Shared Project to various environments (repo). When writing unit tests, I will want ...
35
votes
10answers
8k views

In TDD, should I add unit tests to refactored code?

While refactoring my code using Test Driven Development (TDD), should I keep making new test cases for the new refactored code I am writing? This question is bases on the following TDD steps: Write ...
4
votes
2answers
132 views

Testable documentation

I'm creating a library, and I would like to provide a tutorial on how to use the library. Such a tutorial will contain code snippets as usage examples; therefore, I would like to test these snippets ...
35
votes
11answers
6k views

Unexpected Code Coverage Reduction

I am adding unit tests to some existing code which initially was not tested at all. I have set up my CI system to fail builds where the code coverage percentage is reduced compared to previous build -...
2
votes
1answer
175 views

How the MVC increase code testability?

I am learning MVC design pattern as an android developer and I've been seeing that it facilitates the testability of code. I understood this concept, but in real case I'm frustrated. Can someone ...
2
votes
2answers
175 views

What is the difference between unit testing and handling exceptions

I have spent two full days now trying to understand the difference between unit testing and handling exception, but I can't get it. Things I have understood (or I think I have): Unit testing tests ...
5
votes
6answers
411 views

Is testing behavior of many classes in one test still unit testing?

Our project's policy is to write unit tests for single classes only. All dependencies are mocked. Recently we've noticed that this approach makes us vulnerable in such cases: Originally class A looks ...
-1
votes
1answer
207 views

How do sites like LeetCode & HackerRank test your code for correctness?

Not sure if this question belongs here, but I've always wondered how exactly sites like Leetcode & HackerRank test your code. Say you code in Java for a question like, Find all the duplicates in ...
3
votes
2answers
126 views

Bad Practice - having a SUT use a different execution path when in test mode?

I recently ran across some code in a public repo that I'd thought... just plain wrong. The first thing I noticed was /** * Sets a test mode status. * * @param boolean $mode Mode to set */ public ...
2
votes
4answers
444 views

How to test a complex method (without rewriting it in the test)?

When writing tests, I often struggle with a conceptual issue, and maybe I am missing something major here. For many classes, the test writing is straight forward and simple, often tests (and their ...
2
votes
1answer
88 views

How to unit test a service which output is an event with data?

Technologies : NodeJs, Kafka, Mocha The issue : I have a nodeJS service which given a String returns events with a many data. How can I test this using Mocha ? In a simple scenario the service ...
2
votes
2answers
74 views

Best practices for testing settings file with many parameters in simulation code

I'm conflicted as to what is the best way to approach this problem. I am writing a simulation in Python, which is parametrized by ~ 50 parameters. I have a JSON file where these parameters are set, ...
2
votes
5answers
423 views

Is it acceptable to accept multiple results in a unit test?

I've noticed this while implementing a Rest-API today. We first define interfaces for each API method and the api contract for one endpoint allows (amongst others) two status codes: 200 and 204. Both ...
0
votes
2answers
59 views

Design Java Testing class for hierarchical objects

Consider the following POJO structure in my main code. I want to create some testing framework for this kind of hierarchical classes, where the calling test method can specify if they want to modify a ...
2
votes
3answers
195 views

What is the proper logging level for tests?

I raised an issue at my employer concerning our gigantic heaps of testing logs. I raised the issue because I was spending well over a minute to find the relevant logs and stack-trace. I stated we ...
2
votes
0answers
141 views

Is the distinction between Mocks, Stubs and Fakes useful?

Automated software testing professionals often make a distinction between various kinds of test doubles such as Mocks, Stubs and Shim/Fakes. In fact, in the article Mocks Aren't Stubs Martin Fowler ...
2
votes
1answer
77 views

How to increase test granularity without modifying the public interface

First of all, I'm aware that in python nothing is really private but let's assume that we can stick to using the leading underscore to indicate that something is private. I have a module consisting ...
1
vote
2answers
83 views

Unit Testing Complicated Service Call with Many Methods

I am trying to understand principle of Unit testing, Purpose, and Moq. We have complicated Service Call. The Service Call encompasses numerous Repositories and Services, with dependencies and ...
3
votes
0answers
28 views

Decoupling redux reducer tests from state shape

Recently I have been refactoring state shape in a fairly large redux application, and I have found that one of the obstacles to doing to is that the tests for my reducers clearly have a lot of "...
0
votes
1answer
52 views

In clojure, how to structure a simple reverse file search function to make it unit testable

I have the following pair of functions used for searching upwards for a configuration file: (defn has-config? [path] contains? (set (.list path)) "my-config") (defn find-config-path [path] (cond ...
3
votes
3answers
381 views

Purpose of unit testing simple methods

I'm trying out unit testing to see if it works for me, but im having trouble with these little functions. public void OpenNewMenuItem(MenuItemID ID, ITab DataContext = null){ var menuItem = ...
0
votes
1answer
34 views

How to test and what kinds of test to write for Request Handlers that use Repository layer?

Consider class below: class FillTestBySerialHandler { /** * * @var FillTestBySerialRepository */ private $fillTestBySerialRepository; function __construct(...
0
votes
3answers
220 views

Is using pytruth considered Pythonic?

I recently found Googles pytruth package. I am very used to pytest and I am wondering what the value of the way less commonly used pytruth is. The only reason why I didn't directly discard it, is that ...
1
vote
1answer
156 views

how can I unit test my class methods having database calls

I am working on introducing unit testing to a class in my project which is responsible for verifying customers according to a specific criteria. For clarity, let's say one of the methods in my class ...
1
vote
3answers
168 views

What would be an ideal unit test in this simple case?

I have a simple service that fetches an article from the repository. If it finds it then it returns it otherwise throws an exception. In short the function is totally dependent on the database ...
0
votes
2answers
142 views

How do unit tests and integration tests actually run?

There are plenty of resources that explain what unit and integration testing are and why they are important. That is not what I am asking here. I am trying to understand how unit/integration tests ...
-1
votes
1answer
57 views

Unit test Service Class [duplicate]

In my project, I have two type of Service Class : The simple one, they are interface that use the DAOs The complicated one, are Rest Api Service The Rest Service will make call to an API, and map ...
1
vote
2answers
294 views

How should I unit-test trivial one-liners (if at all)?

I've written this set of convenience functions which give nicer names to certain trivial one-line computations. The thing is, I don't feel I can write a test for any of them; anything I write is just "...
0
votes
1answer
144 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
101 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
147 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 ...