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.

1
vote
2answers
171 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
949 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
899 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
543 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
40 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
102 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 ...
1
vote
4answers
4k 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
94 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
1k 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 ...
0
votes
0answers
395 views

C# EntityFramework 6 DbContext and data service with dependency injection

I am refactoring an application that collects and displays measurement data that is stored in a database. Currently I have an interface calleIMeasurementsDataService and an implementation ...
3
votes
4answers
517 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
604 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
1k 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
350 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
179 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
511 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
77 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
291 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
197 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
306 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
979 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
543 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
489 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
123 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
2k 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
935 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
464 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
869 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
171 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
3k 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
609 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 ...
7
votes
5answers
500 views

Can a unit test replace works-on-my-machine when completing work?

I've made a small change to an integration component and have prepared unit tests to cover my work. All new and existing unit tests are passing. It will take a substantial amount of time to configure ...
3
votes
1answer
201 views

How and what to expose of an AVL Tree class for proper testing?

I don't know which methods should be public, because I have the test methods which require a node and a node is something which no one must know about. public static class Node<K, V> //nested ...
18
votes
1answer
2k views

Unit tests: deferred assertions with Linq

Is it ok to add deferred assertions like this var actualKittens = actualKittens.Select(kitten => { Assert.IsСute(kitten); return kitten }); Why? So I can iterate just once even with ...
8
votes
1answer
2k views

Why is unit testing harder in Object Oriented programming compared to Functional programming?

I'm going through this series. The author mentions that since state is maintained in object oriented programming, it is harder to write unit tests. He also says that since functional programming doesn'...
4
votes
2answers
98 views

Is it good practice to stub an object not because it is slow, but to prevent testing it twice?

Let's say, for example, I want to test that a warning is shown on the Dashboard of a Car only when the Engine is broken. The method implementing this functionality might look as follows: class ...
1
vote
3answers
2k views

Not wrapping an IDisposable object in a using statement

I am updating some code to allow us to implement unit tests. What I have so far is a Business Layer which calls the repository to get data from the database. Business Layer example: public class ...
1
vote
1answer
155 views

Practices to build test vs release versions of code?

I've written an application which reads a list of filenames and does stuff on those files. Dynamic allocation is not allowed and our language of choice is C. The app has an array to hold the ...
0
votes
2answers
1k views

Can not understand how dependency injection can ease testing inside asp.net MVC

Each time i read an article or a book about asp.net MVC , there will be a chapter for dependency injection and repository . now i can easily feel the benefits of using repository over hard coding the ...
-2
votes
2answers
105 views

Test-driving list handling functions

I want to test-drive functions in C that manipulate an array. But the solutions that I find make me feel somewhat uncomfortable. Lets speak about the limitations first: I'm using a forward declared ...
3
votes
3answers
702 views

Alternatives for Unit testing

The problem I have with unit testing is that while it makes refactoring(regression testing) easier, it expands the code base and make it more difficult to prototype or to change the design. Developers ...
1
vote
4answers
455 views

Test Command class executing sub commands

I am using Command Pattern to execute actions and so I developed many command classes (CommandA, CommandB, etc.). Now I need a SuperCommand that receives a collection of data from legacy code, loops ...
0
votes
1answer
143 views

Should I unit test ssh outputs?

I have a class that does reboots a machine and then prompts it for readiness. The prompting is done via ssh and the standard output needs to be formatted to verify if the machine is in ready-state. So ...
5
votes
1answer
211 views

Misguided Unit Testing Approach

My organization is investing time in writing the wrong kinds of tests (unit tests that are tied far too heavily to the implementation, are very time consuming to create, and often make the system ...
1
vote
2answers
955 views

Why is white box testing discouraged in OOP?

It seems the general consensus for unit testing classes is to test your object through its public interface only. So if you wanted to test the removeElement method on a LinkedList class you'd need to ...
0
votes
1answer
101 views

Importance of PHP unit tests regarding to basic classes

For 3 months, I've been working on a Web Project using PHP to create a platform to handle remote lights and sensors. I'm currently working almost alone on it, but we will be 2 on it in the next months....
3
votes
3answers
160 views

Handling a validation error

I have an app which accepts two parameters: payment received and cost. It then calculates change denominations. It is an MVP app, which calls a WCF web service, which accesses a Domain Layer DLL. ...
-3
votes
3answers
139 views

Should a Calculator be a value type or an entity type?

Please see the code below: public class Calculator { private readonly int Number1; private readonly int Number2; private readonly int Answer; public Calculator(...