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)

21
votes
12answers
4k views

How does unit testing work?

I am trying to make my code more robust and I have been reading about unit testing, but I find it very hard to find an actual useful use. For instance, the Wikipedia example: public class TestAdder { ...
2
votes
0answers
57 views

How do I test with multiple input combinations?

I have a piece of code that I need to test, which is layered in three parts: Web API Controller Persistence/Logic Layer System calls for persistence It's the basic GET/POST/PUT/DELETE call system. ...
8
votes
2answers
929 views

Unit Testing with massive lookup tables?

Our system is structured in such a way that we get a lot of key info for our calculations and other such logic from lookup type tables. Examples would be all kinds of different rates (like interest ...
-1
votes
3answers
115 views

Who should write Unit Tests? [duplicate]

Should unit tests be written by the developer who wrote the code or someone else ? And how effective is writing units tests as a method of learning a new system ?
0
votes
1answer
90 views

Bad idea to use the same test cases for multiple parts of a contiguous algorithm?

I'm working on an algorithm that's split up into multiple parts, each of which performs different tasks but is more or less separate from the others, by which I mean the only interaction between the ...
5
votes
2answers
123 views

How to setup build system for unit testing + mocking?

We have a legacy code base in entirely C++. Our build system is CMake. My first stab at unit testing was as follows: Define a target (LibraryA). This library contains the code to test. Define a unit ...
2
votes
2answers
81 views

Should unit tests run on every git branch?

I am new to repo management / continuous integration. I designed a repo in the following way PROJ |-src |-include |-lib |-config PROJ_Unit_Tests |-src |-config PROJ_Doc When I now do ...
2
votes
3answers
104 views

Unit testing text output

I have recently become responsible for a legacy tool that analyses code and provides a log as output. As part of the JUnit suite for this, there are ~100 tests that rely on successfully matching the ...
10
votes
5answers
4k views

Are RSpec and Cucumber really worth it?

I know most RoR programmers are testing addicts and I understand the advantages of a large testing suite but when I start testing, I never get such a large suite and I always wonder "Am I testing the ...
0
votes
2answers
116 views

Testable design in Swift

I've been searching for so long about how to design testable classes in Swift but every information site just describe basic stuff like how to test, how to assert, why is testing good... My current ...
1
vote
2answers
187 views

BDD, Cucumber best practices

I'm trying to understand some best practices when it comes to BDD and Cucumber. I've only recently started to use it, and the first feature I have written a test for is testing a search feature, more ...
9
votes
4answers
400 views

What to do when TDD tests reveal new functionality that is needed that also needs tests?

What do you do when you are writing a test and you get to the point where you need to make the test pass and you realize that you need an additional piece of functionality that should be separated ...
5
votes
6answers
2k 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 ...
1
vote
2answers
41 views

Is the use of a constant as a parameter of an Unit Test mocked dependency's method wrong?

We have a Unit Test Case where we want to assert that after a login operation, the SUT is able to call a method on one of it's dependencies. This dependency is a NavigationManager and the expectation ...
2
votes
2answers
540 views

Is there a better way to organize my module tests that avoids an explosion of new source files?

I've got a neat (so I thought) way of having each of my modules produce a unit-test executable if compiled with the -DTESTMODULE flag. This flag guards a main() function that can access all static ...
0
votes
1answer
102 views

Will TDD really save bug fixing time for WPF/MVVM

I'm looking for an update .net 4.5 WPF+MVVM+TDD tutorial for my team. I have found only one good tutorial https://deltaengine.fogbugz.com/?W199 My goal is to learn Test Driven Development using WPF ...
1
vote
1answer
39 views

Website form testing [closed]

My boss has three websites and each of those websites have forms on them that people can sign up for nightclubs. He asked me to look up usability tests, however, I don't think that's what hes ...
0
votes
1answer
277 views

How to test model binding within an MVC controller when Bind attribute with Include list is used?

Auto-generated action methods in MVC5 make use of the BindAttribute with an Include list that contains the field names in a string literal. Example: // POST: MyTable/Edit/5 // To protect from ...
7
votes
3answers
921 views

What should I mock in tests of an application with service tier and DAO tier?

My classes are following this structure Service Tier (creates and maps InputDTO to DB Data) DAO Tier (actually executes DB calls) When I write service tier JUnit tests, the DAO tier is called, and ...
81
votes
12answers
10k views

Is testable code better code?

I'm attempting to get into the habit of writing unit tests regularly with my code, but I've read that first it's important to write testable code. This question touches on SOLID principles of writing ...
1
vote
2answers
234 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 ...
1
vote
1answer
67 views

Focus of unit tests on code [duplicate]

I discover mocking strategies after 50% of tests was writen, and I'm confused about how much focus unit tests should have, for example on class method. I know that for external dependencies you should ...
7
votes
3answers
92 views

How to write tests that make sense for visualization software?

I have a fairly large piece of software which takes certain file types and visualizes them / creates a host of buttons for manipulation of the image plotted. I feel like I'm finding bugs / pieces of ...
0
votes
1answer
52 views

Unit testing implementation vs behaviour

Is it possible to write a unit test (as opposed to an integration test) in the following scenario: I have a list of Foo objects, some of which already exist in the database, some don't I want to ...
23
votes
9answers
2k views

What are the disadvantages of writing code before writing unit tests?

I have always seen the recommendation that we should first write unit tests and then start writing code. But I feel that going the other way is much more comfortable (for me) - write code and then the ...
23
votes
5answers
9k views

What are the design principles that promote testable code? (designing testable code vs driving design through tests)

Most of the projects that I work on consider development and unit testing in isolation which makes writing unit tests at a later instance a nightmare. My objective is to keep testing in mind during ...
5
votes
5answers
2k views

Why do I need unit tests for testing repository methods?

I need to play devils advocate on this question a bit because I cannot defend it well because of lack of experience. Here is the deal, I get conceptually the differences between unit testing and ...
77
votes
10answers
6k views

How to motivate co-workers to write unit-tests? [closed]

We're working on a large product which has been in production for about 5 years. The codebase is.. erm.. working. Not really well but it is working. New features are thrown into production and tested ...
7
votes
4answers
267 views

Testing a Conversion class

I have a class that is responsible for performing conversions from/to twenty-something types. Let's call this class ConvertUtils. For C# programmers out there - this class expands .Net's Convert ...
0
votes
2answers
56 views

Avoid FileUtil that is made for tests [closed]

I'm constantly creating util classes like Files to be able to mock files functionality in tests. It is convenient but violates basic idea - don't modify production code to comply with tests. I could ...
0
votes
4answers
119 views

Unit Testing for mapping int to string

How should one unit test a function which (among other things) maps an integer to a string? If the function were to map 0 => string0, 1 => string1, 2 => string2, should I test for each of 0, ...
2
votes
3answers
254 views

How much should I break up my unit tests?

I recently learned about unit tests and TDD and have started going back to add unit tests to my code (and thank god, it's proven that some things I've written are much more broken than I thought). ...
2
votes
1answer
77 views

Javascript unit testing - mocks or fixtures?

Interested in some opnion... I'm introducing unit testing of JS into a team, it'll largely be testing modules with many dom interactions and updates. Traditionally I've always used mocks and spys ...
44
votes
11answers
14k views

What are the disadvantages of automated testing?

There are a number of questions on this site that give plenty of information about the benefits that can be gained from automated testing. But I didn't see anything that represented the other side of ...
1
vote
3answers
118 views

Unit testing functions calling other tested functions [duplicate]

I have three functions: ValidateUsername(), which determines if a string is a valid username according to some rules SetUsername() which sets a string as a user's Username if it passes validation ...
15
votes
2answers
870 views

Shipping test code. Why wouldn't you?

I would like to ship unit tests 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 ...
34
votes
6answers
4k views

How can I write unit tests that simplify feature implementation? [duplicate]

I'm a newbie to working in software development and I read a lot about how cool unit tests are. Now, I've made my first steps into a project where I'm working with a number of equally unexperienced ...
2
votes
1answer
243 views

how to test a generator with unittest?

I have programmed a small iterator in Python: class anything(): def __init__(self): self.i=1 def __iter__(self): return self def next(self): if self.i>100: ...
5
votes
4answers
526 views

How to write a test to cover a bugfix of a segfault

There was a bug that I recently fixed that was causing a segmentation fault (due to an out-of-bounds access). The maintainer of the project is asking me to write a unit test to cover the bugfix. How ...
1
vote
1answer
53 views

What is a good alternative to the TestDataBuilder pattern?

The TestDataBuilder pattern is used in unit testing to create collaborators. Its advantages versus using constructors: Changes to constructors are localized. Test code becomes clearer, because you ...
0
votes
0answers
33 views

Mocking delegate constructors

I am new to Unit Testing in C++. I am supposed to write a Unit test for my code and I am using Google Mock for the same. I have gone through their turtle example. But I am still confused as to how to ...
0
votes
2answers
475 views

Why would a video game need main(String[] args) in its own class? [closed]

My teacher just told me that whenever I create a class to run something for a video game company that uses Eclipse, I should make a run class with the main and any outputs. He says any arithmetic ...
11
votes
3answers
742 views

Unit Testing Competition

My employers runs a monthly unit testing day competition. One entire day is dedicated to writing unit tests -- obviously we do more testing throughout the month, but this is an entire day -- and the ...
2
votes
2answers
84 views

Testing strategy for wrapper class

In my Android project I decided to create wrapper around SharedPreferences(which is basically key-value storage) with following interface interface Preferences{ public void saveInt(int value, ...
3
votes
2answers
289 views

How do you unit test \ use TDD methods for ETL's and reporting projects?

ETL projects are projects created using an ETL (Extract - Transform - Load) tool such as SSIS, PowerCenter,etc These typically involve reading data from an external source, loading it to a staging ...
9
votes
4answers
664 views

What is understood under “unit” in unit testing

As I understand in theory under "unit" people mean method (in OOP). But in practice tests which verify some method in isolation are very fragile behaviour tests (verifying not the result but the fact ...
4
votes
2answers
74 views

How to decide what forms the System Under Test

Ok, so we started with the initial version of "The Art Of Unit Testing" and we do unit tests for classes where every test covers one aspect of one method. This has the drawback of high maintenance ...
12
votes
4answers
1k views

Does test-driven development force me to follow SOLID?

I hear a lot from TDD practitioners that one of TDD's advantages is that it forces developers to follow SOLID principles (Single responsibility, Open-closed, Liskov substitution, Interface segregation ...
0
votes
0answers
65 views

How to verify a method is only called once, with specific arguments (using RhinoMocks)

I'm just starting to use RhinoMocks. Now I'm wondering what test cases I should write. I want to assert that a method is only being called once, with specific arguments. Lets start with my ...
88
votes
10answers
57k views

How do you unit test private methods?

I am working on a java project. I am new to unit testing. What is the best way to unit test private methods in java classes?