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)

7
votes
3answers
2k views

Event Driven Programming: A sequence of unfortunate events

I have a very basic game loop whose primary purpose is to check for updates & changes to a list. I have contemplated using event driven programming to replace the game loop/list idea with an ...
13
votes
5answers
523 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). ...
3
votes
6answers
3k views

Should I use a unit testing framework to validate XML documents?

From http://www.w3.org/XML/Schema: [XML Schemas] provide a means for defining the structure, content and semantics of XML documents. I'm using an XML Schema (XSD) to validate several large XML ...
15
votes
2answers
852 views

Software Testing Techniques or Categories [closed]

What kinds of software testing do you know? I've heard about Test-Driven Development, Unit tests etc, but can't understand their importance and difference. For example, why are we using regression ...
2
votes
3answers
564 views

Testing front-end app that hits a REST service

A lot of questions about testing here... And I have another one. Forgive me, but I want to make sure I do this right. Let's say I have a front-end application, be it a mobile app, or a single-page ...
16
votes
3answers
1k views

Shipping test code. Why wouldn't you?

I would like to ship test code alongside a product. Specifically, provide an option so that anyone with a copy of our program can hit a "self-test" button or pass --self-test on the command line and ...
2
votes
2answers
120 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 ...
72
votes
10answers
19k views

How should I test randomness?

Consider a method to randomly shuffle elements in an array. How would you write a simple yet robust unit test to make sure that this is working? I've come up with two ideas, both of which have ...
1
vote
2answers
132 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 = ...
3
votes
1answer
106 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 ...
4
votes
3answers
170 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
5answers
459 views

How to make one test depend on the results of another test?

Let's say there is a utility class that provides some common static methods used everywhere in your code by many other classes. How would you design your unit tests for the consumers of the utility ...
6
votes
1answer
374 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 ...
31
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 ...
9
votes
0answers
133 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
67 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 ...
-1
votes
2answers
136 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
166 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 ...
177
votes
9answers
16k 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 ...
5
votes
6answers
610 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 ...
2
votes
1answer
57 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 ...
2
votes
4answers
138 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, ...
4
votes
2answers
133 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. ...
40
votes
7answers
21k views

Difference Between Unit Testing and Test Driven Development

From reading the descriptions, I understand that in TDD tests are done prior to writing the function and in Unit Testing, its done afterwards. Is this the main difference, or the two terms can't even ...
2
votes
1answer
121 views

Eclipse unit test - one project per file/class?

My new company has never had unit testing, but have finally been persuaded to introduce it. They have chosen Google test and, for some reason, want to run the unit tests from within Eclipse (where I, ...
6
votes
1answer
137 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 ...
0
votes
4answers
627 views

Should I use TDD and BDD if my project is changing fast?

I have my own little project I am creating using RoR, I plan it to have small-medium load. With no doubt I started with BDD and TDD (Cucumber and RSpec to be exact, but I am also experienced with ...
4
votes
2answers
111 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 ...
34
votes
5answers
7k views

Is there a point to unit tests that stub and mock everything public?

When doing unit tests the "proper" way, i.e. stubbing every public call and return preset values or mocks, I feel like I'm not actually testing anything. I'm literally looking at my code and creating ...
0
votes
1answer
161 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(); ...
23
votes
11answers
2k views

Automated Testing: Explaining its Business Value

To start I don't think this is a repeat of other questions on unit testing. What I'm looking for help with is articulating its value to a team of programmers, analysts, managers and testers. By ...
7
votes
3answers
345 views

Long-Term Strategy For Implementing a QA System?

I have been given the task of implementing some QA testing into a massive existing system. We're going to start out with system-level tests and might add unit tests if it is deemed necessary. I ...
32
votes
10answers
5k views

Should we test all our methods?

So today I had a talk with my teammate about unit testing. The whole thing started when he asked me "hey, where are the tests for that class, I see only one?". The whole class was a manager (or a ...
4
votes
1answer
396 views

Unit testing Eloquent outside of Laravel

How can I unit test my Eloquent models when I'm using the ORM outside of Laravel? What I'm hoping to do it run tests on each model but somehow mock the database connection/query/builder(?) object. ...
0
votes
1answer
103 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 ...
29
votes
12answers
7k views

How much Code Coverage is “enough”?

We are starting a push for code coverage here at my work, and it has got me to thinking.... How much code coverage is enough? When do you get to the point of diminishing returns on code coverage? ...
0
votes
1answer
233 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 ...
1
vote
0answers
27 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
94 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
79 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
64 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
215 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
163 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
107 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, ...
4
votes
1answer
60 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 ...
5
votes
3answers
194 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 ...
0
votes
0answers
51 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 ...
1
vote
2answers
443 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 ...
3
votes
2answers
140 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 ...