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)

37
votes
9answers
4k views

Do we need Logging when doing TDD?

When doing the Red, Green & Refactor cycle we should always write the minimum code to pass the test. This is the way I have been taught about TDD and the way almost all books describe the process. ...
2
votes
3answers
277 views

C++ project organization to reduce unit testing build time

I want to organize tests for a project large enough that build time matters (especially for the CI server). Say I have this code that I would like to test : //foo/greet.cpp #include <stdio.h> ...
0
votes
1answer
195 views

Mixing declarative & imperative code (Implicit 'unit tests' ?) [closed]

Well I'm no expert, but as a student, I'm curious about languages and their design patterns / goals. I'd like to know, whether there are any points I miss in the following examples, and why ...
0
votes
1answer
172 views

What kind of a test is a “consistency check”?

Some or all of the tests I write and run are checks for consistency e.g. assert that if I create a new user account, that the account that was created actually has the same name as the name that was ...
4
votes
6answers
1k views

Are HSQLDB unit tests an anti pattern?

HSQLDB is great. It (also) has an embedded mode (no dedicated server needed), which allows for quick prototyping of stuff like Proof of Concepts, and it can also be great in production-ready ...
2
votes
1answer
589 views

equals and hashcode methods autogenerated, is it always a good practice?

Preamble: Let's say I aim to cover all my classes with test coverage. Despite the common opinion (expecially in Java community) to "not pay too much attention to Cyclomatic Complexity (CC) and code ...
62
votes
10answers
4k views

Does it make sense to write tests for legacy code when there is no time for a complete refactoring?

I usually try to follow the advice of the book Working Effectively with Legacy Code. I break dependencies, move parts of the code to @VisibleForTesting public static methods and to new classes to make ...
4
votes
8answers
510 views

How to measure that a team is doing Test Driven Development

My team is considering a department goal of doing Test Driven Development next (fiscal) year. TDD sounds good and my manager is on board. The only problem is measurement. Our company rules require ...
1
vote
5answers
431 views

Should unit-tests be entirely self-contained? [duplicate]

As the title suggests my question is whether or not unit-tests should be entirely self-contained or can one rely on the results yielded by previous tests? What I mean, in case that it isn't entirely ...
21
votes
7answers
847 views

Should I have unit tests for known defects?

If my code contains a known defect which should be fixed, but isn't yet, and won't be fixed for the current release, and might not be fixed in the forseeable future, should there be a failing unit ...
4
votes
2answers
170 views

Unit tests tactics

The only unit tests tactic I'm familiar with is comparing against golden data _ a predefined set of input data for which output is known (preferably including corner cases). I cannot think of any ...
1
vote
1answer
358 views

Unit testing methods with logical dependencies on other classes

Suppose I have an interface declaring the following method signature: SearchResults SearchProducts(string type, string filter, string anotherFilter); Inside a concrete implementation of this, I ...
1
vote
4answers
584 views

What are the valid test cases for method calls within if-else condition

I have a discount service that gets called if certain conditions are met. I need to write test cases to check if the discount service is called. My doubt is checking if the discount service is NOT ...
16
votes
8answers
1k views

What are good unit tests to cover the use case of rolling a die?

I'm trying to get to grips with unit testing. Say we have a die which can has a default number of sides equal to 6 (but can be 4, 5 sided etc.): import random class Die(): def __init__(self, ...
0
votes
0answers
95 views

Model Driven Design with Bean Validation

If I have a rich domain library that gets included into a Java web application, but I want to achieve a level of dependency isolation with that domain library such that it is possible to build and ...
0
votes
0answers
386 views

How to integrate unit testing process into legacy software development process? [duplicate]

I'd like you to share your insights of how have you successfully turned the direction of rotting legacy code base to modular application design where it's easy and useful to add unit tests? What I'm ...
0
votes
2answers
117 views

How should I test the functionality of a function that uses other functions in it? [duplicate]

Suppose there is a function get-data which returns a map of information about the id of the user passed in. now this function uses 3 functions source-a, source-b and source-c to get three different ...
10
votes
3answers
563 views

How do I stress the importance of unit tests to my manager [duplicate]

I've recently started a new job, & I've been tasked with completing a feature that another developer didn't finish before he left the company. The existing tests are out of date (i.e ...
10
votes
4answers
673 views

Is there a better way of writing unit tests than a series of 'AssertEquals'?

Here's a basic example of what my unit test needs to be, using qunit: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> ...
0
votes
2answers
291 views

How do I read the Entity Framework Model and validate it against a given connection?

I have a Entity Framework Database First Model. I want to write a MSTest/nUnit test to verify that all the stored procs, tables and views that are defined in my edmx model are still valid on the ...
0
votes
0answers
81 views

Unit Testing in iOS — Should I split out my Data Model into it's own class?

I'm attempting to try out using unit test in for the first time in new iOS activity for work. I love the idea of unit testing, but always find the specifics to be... messy. I get the general ...
-1
votes
1answer
121 views

How should I test my application? [closed]

I have made a simple application which searches for files and folders on users computer. Since, I am a student currently in my 1st year and don't have any formal training and have made my application ...
3
votes
2answers
286 views

How do I integrate a browser-based JavaScript unit testing framework into my workflow?

I'm wondering how I seamlessly include a JavaScript unit testing framework into my workflow. The context is, we have an existing data processing algorithm + webapp to display it, with no automated ...
2
votes
0answers
73 views

How to manage success dependency between unit tests [duplicate]

How do you manage the dependency of one unit test on another unit test succeeding? So, supposed I have a class and this class has say 5 methods. I create like 2 dozen unit tests (test methods) for ...
1
vote
2answers
191 views

TDD - Making assertions about C# Expression trees

How would you unit test the PerformUpdate method in the sample below? This is a (very) simplified version of some code that performs updates against a database where the schema is dynamic and ...
7
votes
1answer
4k views

How do I decide what testing framework to use?

The situation is this. I'm a junior developer for a small government IT project. We don't have anything of continuous integration or a automated testing framework. But the idea is to be developing ...
3
votes
2answers
202 views

TDD workflow for (implementation specific) edge cases

When developing features with TDD, I create a test for each combination of feature and case. So, one test for creating user successfully, one for validation errors, and one for database errors. I ...
1
vote
3answers
1k views

How to use mock objects [C++] without passing them as arguments to functions

I'm in the process of integrating a Unit Testing Framework for an existing code base in C++. I've zeroed down on CxxTest, but as it turns out we can use other Mocking Frameworks (like googlemock) in ...
36
votes
7answers
3k views

Is it sufficient to use acceptance and integration tests instead of unit test?

Short introduction to this question. I have used now TDD and lately BDD for over one year now. I use techniques like mocking to make writing my tests more efficiently. Lately I have started a ...
2
votes
1answer
154 views

How can I automatically test a large, complex spreadsheet?

So, I've inherited one of those "Engineer's Special" spreadsheets -- the kind developed by Mort the Engineer, with lots of hairy VBA and WTF, complicated calculations, and no documentation. ...
3
votes
1answer
114 views

Testing: Should I wrap system notifications and send my own?

In the current Cocoa app I'm working on, I've got an object, RecordScheduler, which responds to two types of notifications, "day did pass" and "quicksaving interval did pass". In both cases, the ...
3
votes
2answers
268 views

Unit testing method name standard for overloaded methods

I have read several posts which discuss coding standard for naming the unit test methods for improving readability. I follow this NameOfMethod_ExpectedBehavior_WhenSomeScenario, but now I am confused ...
15
votes
6answers
1k views

TDD and complete test coverage where exponential test cases are needed

I am working on a list comparator to assist sorting an unordered list of search results per very specific requirements from our client. The requirements call for a ranked relevance algorithm with the ...
16
votes
6answers
1k views

what kind of functions and/or classes are impossible to unit test and why

Main excuse from the developer for not having a good unit testing is "Code is not designed in a unit testable fashion." I am trying to understand what type of design and code that can't be unit ...
3
votes
2answers
289 views

Writing a unit test for a platform dependent unit

I have a method to be tested which depends on the OS, what's the best approach for testing the method depending on the OS? Is it to test on every OS that I have I require? Is there a better approach ...
4
votes
1answer
375 views

Understanding unit testing concept

I've just started writing unit tests and I'm not sure am I doing it the "right way." Should I test every class "by removing dependencies"? In other words, does unit testing mean: "test part of a code ...
7
votes
2answers
274 views

To load or not to load data for unit tests from external files

When unit testing I often find myself debating how much of the data I feed to, and expect back from my units under test, I should include in the actual test files. The tradeoff I constantly ...
4
votes
1answer
309 views

Inheritance in test classes

I have an interface Serializer with methods serialize and isSerializerFor. I created a first implementation of this using TDD, and ended up with a nice clean test case fully covering a nice clean ...
1
vote
1answer
112 views

Loading data for ShoppingCart item

I'm currently trying to cover our shopping cart with unit tests. Class ShoppingCartItem has property Term. It also loads available terms for this item upon object creation. Currently this is done ...
1
vote
2answers
177 views

Testing Framework Selection: xUnit family theory

Background: I am familiar with xUnit family frameworks and have had experience with (shunit2, PhpUnit and simpletest). I am currently trying to find a testing framework for C++. I did a quick search ...
6
votes
3answers
2k views

How to mock method with hard coded object?

I am working on an application which have multiple layers. Data access layer to retrieve and save data from data source, business logic to manipulate data, user interface to show the data on screen. ...
5
votes
1answer
175 views

Managing false positives in TDD or BDD

I'm relatively new to TDD and have been thinking a lot about how to manage the perpetually growing pool of tests that comes with it. One of my biggest concerns is about false positives. In my ...
2
votes
1answer
286 views

When NOT to unit test? [duplicate]

I am hitting a stumbling block with TDD flow. We are using PHPUnit+FuelPHP and I am stuck on how to write a unit test for our image upload/cropping feature. FuelPHP is notoriously hard to unit test ...
3
votes
3answers
152 views

Should test fixtures be added to code repositories?

I'm unit testing some code that processes data from an external API. That external API serves up a large pile of JSON data. The right thing to do here, of course, is to use fixtures in the unit ...
8
votes
2answers
390 views

Unit testing side effect-heavy code

I'm starting to write C++ code to run a robot, and I don't know how to incorporate unit testing, if indeed I can. I have been provided with a library which allows the creation of "commands" for the ...
0
votes
2answers
285 views

Unit test DAO code using SQL Lite when the application database is Oracle

We have an application with Oracle backend. The DAO layer is written in C# and uses nHibernet to perform the data operations. To unit test our DAO code, we use SQL Lite which creates the database ...
6
votes
3answers
297 views

Unit (regression) testing scientific algorithms given floating point behavior

I have been working on a project and running into a very difficult problem. The problem can be stated simply as how to unit-test numerical algorithms. However if you just took this simple statement ...
0
votes
1answer
289 views

How would you create useful tests for Oracle BI Publisher reports?

I'm curious about how to test reports that seem rather straightforward. I'm supposed to create test cases for an Oracle report(XML Publisher/BI Publisher). So for example, a report is supposed to just ...
9
votes
6answers
2k views

Why did Java make package access default?

I'm asking this question because I believe they did it for a very good reason and that most people do not use it properly, well from my experience in industry so far anyway. But if my theory is true ...
2
votes
3answers
307 views

How should I go about bringing this code under test?

I'm working on an open-source test framework. 90% of my codebase has good test coverage. My main problem area is the command-line entry point. This module began life as a very short script for ...