Stack Exchange Network

Stack Exchange network consists of 175 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.

3
votes
1answer
78 views

How to conduct software verification on embedded product?

I have developed an embedded product, which has a dot-matrix LCD, some buttons, bluetooth and WiFi functions. To me, the functions are rather complicated as one of the operating mode can interact or ...
0
votes
2answers
2k views

How do I go about unit testing a private method that gets called in a loop like this one? [duplicate]

How do I go about unit testing a private method that gets called in a loop like this one: // Calls MethodToUnitTest in a loop public static string Generate(params int[] values) { ...
1
vote
2answers
4k views

How to pass a mock as std::unique_ptr to Class under test

I am writing some test units using googletest and googlemock and I am stuck in a problem related to C++11 smart pointers and polymorphism. Suppose you have those classes: class A { public: ...
0
votes
3answers
657 views

Why are no parameters better than few parameter methods?

In Clean Code, Robert C. Martin states that no parameter methods are better than those with very few parameters. I'm kind of confused as no parameter methods are usually harder to unit test and tend ...
8
votes
4answers
563 views

Is implicitly depending on pure functions bad (in particular, for testing)?

To extend a bit on the title, I'm trying to get to some conclusion about whether it is necessary or not to explicitly declare (i.e. inject) pure functions on which some other function or class depends....
0
votes
1answer
134 views

Does it make sense to combine code coverage result for unit test and e2e test

In my company,There is a KPI about code coverage. We measure results by code coverage percentage. So we combine code coverage result of unit test and e2e test together. Is it make sense to do this ?
3
votes
3answers
1k views

Should Integration test offer more value than unit tests? [duplicate]

In order to ask this question I need to define a couple of terms to ensure everyone reading it is on the same page: Unit testing is the testing of a single class with all dependencies mocked / ...
7
votes
2answers
4k views

Testing - In-Memory DB vs Mocking

When writing tests, why would someone want to use an in-memory database over just mocking the data? I could see that in-memory databases could be beneficial for testing out one's repositories. But ...
1
vote
1answer
1k views

Testing a private method in Java [duplicate]

I am new writing good test cases, so please bear with me. Writing a test case for private methods public Stock getStock(String stockTicker) { Stock company = new Stock(); ...
13
votes
9answers
19k views

Should one test the values of an enum using unit tests?

If you have an enum with values only (no methods as one could do in Java), and this enum is part of the business definition of the system, should one write unit tests for it? I was thinking that they ...
6
votes
2answers
188 views

Should I use my own application's abstractions for test setup?

When doing test setup, is it better to use low-level APIs to get my system in the right state, or use the same abstractions that my application would use? I'm specifically interested in what promotes ...
1
vote
1answer
231 views

Testing strategy for a messy codebase

On an entry level for a codebase you are not familiar with, how do you introduce testing, an at what levels ? When introduced to codebases with no tests at all and at the same time being tangled ...
3
votes
2answers
202 views

How/if to test basic combinations of already tested functions

Sorry for the long-winded question. I hope the question and its potential answers can serve as a useful example to developers who are wondering where to set the bar regarding testing fairly simple ...
4
votes
2answers
469 views

Unit Test : Do I need to make an unit test for each class in my project

I have recently tried to to implement unit tests on a Java Web Application my project is built on MVC design architecture and uses Spring & JPA Hibernate and JSF here is a package tree -src -...
4
votes
3answers
3k views

Integration Testing: Testing Service to Service

I'm looking for some advice on testing strategies for service to service communication. I have one service (service A) that makes a call to another service (B) - which is a rest API. Both services ...
6
votes
4answers
687 views

Are unit tests written purely to satisfy a code coverage figure technical debt?

For reasons lost in the mists of time, your project has a code coverage standard. Unfortunately, some new code has gone in which takes the coverage below this figure. John Doe is duly assigned to ...
2
votes
1answer
144 views

Should I unit test my Cucumber helper functions/classes?

I'm very new at writing Cucumber tests. I'm writing Ruby helper functions to assist Cucumber step definitions. Should there be a separate set of tests to test my helper functions i.e. unit tests? The ...
5
votes
3answers
426 views

Unit testing private calls, or not

I have this method, which has multiple private calls: GetConfigStatuses(), ApplyFilters(), GetConfigListInfo(). Since these do not expose anything public I cannot test them like I would a public. ...
1
vote
2answers
177 views

Writing basic unit-tests inside the class file

In Python it is common to have "doctests" - simple tests inside the documentation of classes and methods. Their main advantage is that they can easily be executed while editing the code - when I ...
2
votes
3answers
1k views

TDD a card game - where to start?

One of the most important rule in TDD is to write the simplest test to implement the simplest code in order to get closer to the end of a project. I'd like to implement the game of Briscola. It's a ...
0
votes
2answers
1k views

Test case for Restful API with connecting database is Unit test or Integration Test

I have a restful api router , where it connects with database and returns some rows. So is it Unit test or Integration test ? From my knowledge, unit test doesn't connect with external services likes ...
8
votes
2answers
544 views

How to deal with test passing from the start in TDD

I'm trying to practice TDD in my personal project and I wonder how to deal with the situation when after adding new test it pass from the start based on existing implementation? On the one hand the ...
0
votes
1answer
1k views

Unit testing when you have no getters and setters

I'm a student and I'm learning about domain driven design. From my reading, an important part is removing the getters and setters from a class (thus keeping the implementation of that class private). ...
0
votes
2answers
41 views

Unit testing mapped properties, inside service

Consider this simple method. public async Task AddItem(TodoItem item) { if(item.DueAt < DateTime.Today) { item.ValidationMessages.Add( "The date is missing!" ); ...
-1
votes
1answer
109 views

Proper way to deploy and test ASP.NET applications with databases in 2017

I'm currently developing a quite large ASP.NET application which uses SQLExpress as the underlying database. The project is currently under heavy development and is covered with unit tests and ...
2
votes
4answers
5k views

Testing a function that uses random number generator

I have a method which is a part of the interface I am implementing. This method calls another private method which uses a random number generator to produce output and returns it to the calling method....
1
vote
1answer
97 views

Test whole application or parts of it? Or the other way round? [duplicate]

I am writing a small-ish console application. I took care to be able to test the important business parts of it in Unit Tests. But having most of it finished I realized I could just test the ...
3
votes
1answer
2k views

Definition of brittle unit tests

I've seen the terms brittle and fragile used to describe poorly written unit tests. But I haven't been able to find a clear definition for what brittle or fragile actually mean in this context. Is it ...
3
votes
4answers
552 views

Unit testing Systems with Logic Tightly Coupled with Data

I understand there are many questions in this site revolving around the same concept, but I could not get a precise answer for my case. Problem I am handling an ERP System, with code base in both: ...
9
votes
6answers
621 views

Should unit tests only cover 'functional' software

We are using StructureMap in a new software development project. One of the team members has implemented a unit test that basically tests the StructureMap container configuration. It does this by ...
3
votes
2answers
2k views

Using Custom Asserts in Unit Tests

I asked a question on here earlier and Laiv shared the following link. In the article; it is stated that Eric Evans avoids .equals methods on Entities. In this question; the accepted answerer talks ...
2
votes
2answers
373 views

What are the drawbacks of modeling (unit) test fixtures in JSON instead of using ObjectFactories?

When writing java tests for an application, be they unit tests or testing a broader scope, the java community tends to model fixtures in terms of object factories that produce fixtures of a defined ...
4
votes
3answers
182 views

TDD: Testing coordination of object-graphs provided by third-party libraries

It seems there are lots of resources on how to Mock third-party code when that code is simple. A JSONRequest, etc. but when using a third-party library which requires the configuration of a relatively ...
1
vote
2answers
585 views

How to make complex business logic with lots of dependencies better testable?

This is something hat has been rolling in my mind for quite some time now, but I still haven't found a good approach to it. So here's the thing. We have a server application that has quite a few ...
0
votes
2answers
138 views

Little logic should be test?

I have several classes that looks like: (some of them have dozens of cases) function __construct($value) { switch ($value){ case "1": $value = Values::One; break; ...
0
votes
1answer
78 views

What to test in this module?

Aside from the probable dozens of bugs you can spot in the code below, I'd really like to know what would most people would consider testing in the code below. I have 8 similar exported functions, so ...
1
vote
1answer
309 views

What level of unit testing in a controller that simply calls ViewFactory to get Model

I have implemented a ViewFactory to seperate the generation of View Models from the Controller logic. The ViewFactory implementation has a comprenhensive set of unit tests that cover all paths. As ...
1
vote
4answers
198 views

Avoiding exposing property in order to satifsy unit test

I'm using dependency injection to supply one of my classes (SomethingManager) with something it needs (SomethingEngine). In the constructor of the SomethingManager I set some properties on ...
0
votes
2answers
318 views

Test Driven Development in Research

I spend most of my time analysing data and developing machine learning algorithms with data. As a result, I spend most of my time coding but I never have fixed specifications. Rather, I start with a ...
-2
votes
2answers
1k views

Unit Testing a dictionary result

I often read that each unit tests should test one logical 'thing'. What do I do when the return value of a function is a dictionary? Usually I equality check the entire dictionary against an ...
1
vote
1answer
641 views

Unit testing rabbitmq messaging library?

I'm having trouble figuring how I would test a library that intended to be used for communicating with another web service. For example, I have a Messenger class that initializes a connection and ...
1
vote
1answer
570 views

How to write a unit test for a range (let's say Percentage)?

Imagine I have a class representing a percentage. This class provides self validation through exceptions by not allowing values less than 0 or greater than 100 respectively. When following TDD the ...
0
votes
1answer
128 views

How to avoid explicit naming of source files in unit tests

I'm using CMake to build my application and CUnit to test it. And I was wondering if there is a way to avoid including the production source files directly from the test code by name (#include ../src/...
1
vote
5answers
3k views

Should automated unit tests be part of the build?

Should automated unit tests be a part of the build process, or should they be manually run when someone makes changes to the code instead? To me it seems like making it part of the build rather than ...
2
votes
2answers
1k views

TDD: Decouple test code from production code, avoiding one-to-tone correspondence. Explanation and code examples

I try to understand better under what circumstances one-to-one correspondence between test code and production code is not needed, after reading Uncle Bob's TDD Harms Architecture. For example, first: ...
4
votes
1answer
486 views

TDD: Code example and detailed explanation of “As the tests get more specific, the production code gets more generic.”

I try to understand better what the statement below means on Uncle Bob's TDD Harms Architecture, "As the tests get more specific, the production code gets more generic." Below is my understanding ...
3
votes
5answers
1k views

Is it bad practice to supply command line arguments for unit tests

I am on C++ and using gtest as the main framework. Say I have a edge detection function I want to test that takes an image as an input and returns the edge detected image. I have 3 images ready to be ...
4
votes
1answer
202 views

Boundaries of unit testing between my code and a library or sub-component

Background: I am new to testing in general, and have been studying it in context of JavaScript, specifically React.js, front-end development (actually new to this as well). For the question, I have ...
1
vote
4answers
4k views

Should I use virtual methods to make mocking possible?

So far I have used to write interfaces to those classes I want to mock/fake. Reason for that is that those classes don't have any virtual method to overwrite. But resently I have figured out that I ...
0
votes
2answers
611 views

How did software engineers test their code in 19xx? [closed]

There is a plethora of tools available for engineers to test their code these days. However, frameworks like Mocha.js came around only in 2011 with the ascent of NPM. So I wonder what were the ...