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

learn more… | top users | synonyms (1)

3
votes
3answers
148 views

How do you test a selenium framework?

I have a very large selenium test framework I use to test a web application. It it built around a page-object pattern. This week I fixed a bug in a low level piece of the framework, but it broke many ...
1
vote
2answers
157 views

how to unit test constant that define an implementation detail?

How do I unit test a constant that define an implementation detail? and should I? For instance let's say I have the following class: class A { private Cache _cache; const int ...
3
votes
2answers
214 views

How unit test service method that use repository method

For service methods that call repository methods to interact with database how could I unit test these service methods? For example, public function updateSlideshow($data){ // do some logic ...
8
votes
3answers
429 views

Anonymous namespaces make code untestable

Here is a typical C++ code: foo.hpp #pragma once class Foo { public: void f(); void g(); ... }; foo.cpp #include "foo.hpp" namespace { const int kUpperX = 111; const int ...
5
votes
2answers
965 views

Should I write automated unit tests that fail when the code changes?

Generally when writing automated unit tests (eg JUnit, Karma) I aim to: cover all the boundary conditions get a high level of coverage. I heard someone say: coverage and boundary conditions ...
13
votes
5answers
531 views

Broken Old/Legacy Unit Tests

I work for a big company and I'm responsible for a large java application with thousands of junit tests. Since I moved to this role, there have been 200-300 broken tests (likely broken for years). ...
2
votes
2answers
148 views

Having a TestContext to test methods instead of Dependency Injection

I am working on a legacy code base and I need to find a way to write unit tests for this project. The project has a three layer architecture (UI-Biz-DAL as we call them) and DAL is totally ...
1
vote
2answers
180 views

Testing using mocking, must I mock all dependencies too?

I have the following method to test: public List<MarkId> getMarkIdList(ICar carDoc) { ICourseCar courseCarDoc = courseCarRep.get(carDoc); List<MarkWag> markWagList = ...
4
votes
3answers
171 views

How narrow should my unit tests be?

Here's an example: I have a chat module in my app, and there's a ChatService class that is responsible for networking, and there's a ChatNotificationService helper class that is responsible for ...
7
votes
1answer
590 views

Unit testing an API client and wrappers

I've been going round in circles trying to figure out the best way to unit test an API client library I'm developing. The library has a Client class which basically has a 1:1 mapping with the API, and ...
3
votes
1answer
123 views

How to move Python doctest examples into another unit test framework?

Years ago AFAIK the mathematitician and software developer Tim Peters discovered that very often the documentation of APIs tends to get out of date over time during the software live cycle, because ...
9
votes
1answer
179 views

Unit testing for data munging pipelines made up of one-line functions

Reading Mary Rose Cook's Practical Introduction to Functional Programming, she give as an example of an anti-pattern def format_bands(bands): for band in bands: band['country'] = 'Canada' ...
0
votes
1answer
81 views

Reusing array with static test data across test classes

I have a Map which takes in an a String key, and an array of custom objects as the value. the map usually contains two entries, and the arrays for both entries never change in terms of data; once they ...
32
votes
9answers
2k views

Is it reasonable to not write unit tests because they tend to get commented out later or because integration tests are more valuable?

I was discussing unit/integration testing with a colleague, and he made an interesting case against writing unit tests. I'm a big unit test (JUnit primarily) proponent, but am interested to hear ...
-1
votes
2answers
137 views

What technique can I use to test my code when code renders out an untestable(?) PDF document?

I have a need to test output of my code before I send the output for PDF rendering. Currently I have decided on a switch statement that does two different things depending on whether I am in ...
0
votes
2answers
176 views

Integration Tests - How much is too much? [duplicate]

First of I'm not sure if I chose the right name for my question, I'm not sure if they are functional tests or integration ( or other ). I'm talking about tests which test (or it should) the app from ...
2
votes
1answer
59 views

Best Possible Way To Write Unit Tests For HTTP Middleware

I am using this go library(https://github.com/abourget/goproxy) to create a custom proxy server app. The app is utilizing several middleware of the following form: MyMiddlewarFunc(ctx *goproxy....
5
votes
6answers
653 views

Is it an overkill to write unit tests for a small code base? [duplicate]

I am the sole maintainer of a code base of about 2000 lines of code. It's not big, but over time the code became so unmaintainable my boss agreed to give me time to rewrite it from scratch. Since the ...
4
votes
2answers
156 views

Mocking a utilities module for unit testing? [duplicate]

I'm writing unit tests for a class that makes use of a general utilities module. In general I want to mock all the dependencies of the class, but mocking some of the utility functions feels weird. ...
2
votes
4answers
143 views

Is it ok to use service locator for ubiquitously used dependencies? [closed]

We strictly adhere to inversion of control in our codebase, but that creates hellish constructors (yes, I know that means our classes aren't cohesive enough, this is a work in progress). The thing is, ...
6
votes
1answer
142 views

Testing procedural code

TL;DR. Writing procedural code within a DB transaction. How can I improve design of the code so it's better testable? In my application I have a service object that perform multiple things within the ...
4
votes
2answers
116 views

Does one need to mock concrete data objects?

I've been working on a large project where much of the code is not under test. I have been able to add some unit tests to functional areas of the code, and also to start mocking services but I have a ...
0
votes
1answer
176 views

Testing a function that only calls one or two other functions [duplicate]

The short version The code As part of TDD, we often end up with functions that follow this pattern: function onSendRequestForSelected() { this.deselectStepsWithRequest(); this....
0
votes
1answer
114 views

How to write unit tests for an application that mostly performs “hard to test” actions? [duplicate]

In my company we develop medical data-acquisition systems. The main functions of each application are: Interface with data-sampling hardware; Save/load collected data to/from files on disk; Perform ...
1
vote
0answers
30 views

Do the terms “unit test” and “integration test” sometimes overlap or conflict? [duplicate]

By my understanding, a "unit test" is a test that makes assertions about the "smallest testable unit" - and an "integration test" is a test that depends on integration with an external system, e.g. ...
1
vote
1answer
99 views

Testing base-62 converter

I have a converter module which encodes non-negative numerics to base 62 strings and vice versa. I'm not very experienced with testing, and I got this so far: Encode Test for negative numbers Test ...
0
votes
1answer
95 views

How big should be an input array to unit test a method with a loop? [closed]

This probably sounds like a dumb question, forgive me if I'm asking this in the wrong place, I'd be happy to delete it if so. I'm sort of new to unit testing and I'd like to learn best practices ...
3
votes
0answers
67 views

How to properly test many methods when main logic is in private method [duplicate]

This is a little bit of follow up question to How to test private methods. I totally agree (and experienced what happens when you try) that we should not test private methods. Sometimes though it ...
1
vote
3answers
253 views

How should you look at unit testing protected members used by the abstract base class?

I have the following class(es) that I want to write unit tests for: public abstract class BaseClass { public bool IsFooBar(Order order) { return order.IsNew && ...
1
vote
1answer
77 views

Unit test structure focused on responsibilities

I'm not going to ask what is the best unit test structure or how to do it again. There are already enough questions about it. Instead I'd like you to tell me what else I could consider in the ...
2
votes
3answers
174 views

Is it considered a bad coding practice to write methods/properties that support (only) testing? [duplicate]

When I write (unit) tests I always try to avoid for example microsoft fakes because then the edit&continue feature no longer works. However this often requires refactoring... and sometimes methods ...
1
vote
2answers
111 views

Unit Testing: Structured vs Unstructured Programming [closed]

Is it possible to write effective unit tests for unstructured code? I was reading through the various answers to this question. It explains the implications of unit testing procedural and OOP code, ...
-1
votes
1answer
124 views

What is the difference between a mock and a test double? [closed]

I was reading an article here on Mocks. I would like to conclude to make my understanding more clear. Anything that can be placed in place of a real object while testing is called a Test Double. ...
5
votes
3answers
215 views

How to reconcile “not mocking what you don't own” with “expectations” in unit tests?

I'm putting together a set of models for use in a Zend Framework 2 application. So, each model has a table class which acts as the interface between the model and database for querying. Using the ZF2 ...
72
votes
10answers
8k views

Are (database) integration tests bad?

Some people maintain that integration tests are all kinds of bad and wrong - everything must be unit-tested, which means you have to mock dependencies; an option which, for various reasons, I'm not ...
-1
votes
0answers
52 views

Unit testings (test smallest piece of code) vs. unit testing (only test public) [duplicate]

So a few time on stackoverflow, I've asked 'how do you unit test this private/internal whatever' and there always seems to be a response of 'you don't'. But this seems to be contradictory to unit ...
4
votes
1answer
64 views

Sharing Unit Tests between several language implementations of one spec?

JsonLogic is a data format (built on top of JSON) for storing and sharing rules between front-end and back-end code. It's essential that the same rule returns the same result whether executed by the ...
1
vote
2answers
604 views

Should I unit test my subclasses or my abstract parent class?

I have a skeletal implementation, as in Item 18 from Effective Java (extended discussion here). It is an abstract class that provides 2 public methods methodA() and methodB() that call subclasses ...
0
votes
1answer
295 views

How to structure a chain of method calls [duplicate]

To keep it simpler for any client of my class, I have put a sequence of private method calls within one public method. The client then calls this method and all the methods within run to complete the ...
3
votes
2answers
142 views

Better To Call In Dive Into Submethods Or Pass Around a result

I have a service that does fairly complicated business logic when it receives a request. I have most the functionality isolated into private methods which dive a couple levels down from the method ...
7
votes
2answers
285 views

Can I check the existence of an annotation in an unit test?

I have a java class hierarchy that are formed by an Abstract class and N extensions of it. In the abstract class I have a method that is annotated with a @Remove annotation. While we won't get any ...
0
votes
1answer
132 views

TDD - Outside In developemnt

I'm pretty comfortable with the core concepts of Outside In (especially from this question). However one thing eludes me concerning the mocks you created at each level which then lead to creating the ...
0
votes
1answer
465 views

Should I use a mock or create a new instance of an object in unit tests? [closed]

I have to write a unit test for a method like: void doSomethingWith(Country country) {...} There are the following classes: Interface: public interface Country { String getName(); ... // and ...
1
vote
0answers
31 views

Dealing with stubbed external dependency

In sut I should I have two kinds of dependencies to be stubbed: 3rd party dependencies (mongodb & co) and own dependencies: var async = require('async'), // This dependency should not be stubbed ...
1
vote
2answers
186 views

Ways of creating expected object for assert

Recently, I started to use TDD. It's really cool and fun but creating expected object for assertEquals is very boring and tedious. At the moment I see only two way for that: Straightforward Creating ...
0
votes
1answer
285 views

How to test an algorithm with multiple inputs?

I want to check group of algorithms which has up to 8 input options. The native idea would be to check all possibilities via brute force. How can I reduce it without leaving out required combinations? ...
16
votes
4answers
664 views

How to write maintainable, not brittle, unit tests for a GUI?

I tried writing UI unit tests for my GUI apps and I face the problem that, while they work well when I initially write them, they turn out to be brittle and they break whenever the design changes (...
178
votes
9answers
17k views

Is it normal to spend as much, if not more, time writing tests than actual code?

I find tests a lot trickier and harder to write than the actual code they are testing. It's not unusual for me to spend more time writing the test than the code it is testing. Is that normal or am I ...
8
votes
2answers
540 views

Doesn't dependency injection push the testing burden further down the chain?

I'm learning about dependency injection and while I can see the appeal of it when writing functional libraries, I fail to see how it solves anything when you'll also be the one using the libraries. ...
-2
votes
3answers
170 views

TDD/BDD: Mocks with expectations: bad? [closed]

Is using mocks in the following way a bad idea: writing tests where mocks expect certain calls from the subject under test Or even just writing mocks that return values to the subject under test if/...