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)

5
votes
4answers
553 views

Test Driven Development: A good/accepted way to test file system operations?

I am working on a project at the moment that generates a table (among other things) based on the contents of a file-system, and and in turn does some meta-data modifications on the things it finds. ...
3
votes
6answers
262 views

How does TDD address interaction between objects?

TDD proponents claim that it results in better design and decoupled objects. I can understand that writing tests first enforces the use of things like dependency injection, resulting in loosely ...
3
votes
3answers
235 views

Are branches in unit tests bad practice?

Say I want to assert that a certain option menu is displayed in the front-end of a project. The menu is on screen X and I have to first select data in Y to get to X. Now, it doesn't matter at all what ...
1
vote
1answer
213 views

Unit-testing databases: test all possible permutations of read and write to table?

I am testing a resource management class that is interacting with a database or a file system, or a combination of both. I was wandering if it is the norm to test all possible permutations of read and ...
19
votes
3answers
2k views

Difficulties With TDD & Refactoring (Or - Why Is This More Painful Than It Should Be?)

I wanted to teach myself to use the TDD approach and I had a project I had been wanting to work on for a while. It wasn't a large project so I thought it would be a good candidate for TDD. However, I ...
2
votes
1answer
162 views

Rethinking testing strategy

Working on Plone projects our team tries to achieve full test coverage at least for important products. The kind of tests we write are unit tests, functional tests and integration tests. (Also ...
15
votes
5answers
2k views

Should you hard code your data across all unit tests?

Most unit testing tutorials/examples out there usually involve defining the data to be tested for each individual test. I guess this is part of the "everything should be tested in isolation" theory. ...
3
votes
4answers
550 views

Is spying on tested class bad practice?

I am working on a project where class internal calls are usual but the results are many times simple values. Example (not real code): public boolean findError(Set<Thing1> set1, ...
1
vote
1answer
1k views

Generic repository unit testing best practice?

How can I unit test my generic repository? Unit testing code: [TestClass] public class UnitTestLanguage { private IUnityContainer _unityContainer; private IUnitOfWork _uow; private ...
13
votes
1answer
1k views

How do I test a file reader?

I am working on a project with a few file formats. Some formats are specified by .xsds, others by documentation on their respective websites, and some are custom in-house formats that have no ...
1
vote
1answer
213 views

Unit testing methods which access an Internet API

Hi I'm developing a Wordpress plugin which accesses a couple of API's (Amazon Product API, Flickr, Freebase, Ebay). I've already started writing unit tests for it but I'm still wondering if its ...
1
vote
2answers
351 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
2answers
115 views

How to do you judge the value of using TDD or plain unit testing in an Open Source project? Is there a good rule of thumb? [duplicate]

In my current OSS project, I knew literally nothing about what I was doing when I began. I was integrating with a larger project as a plugin, and that in and of itself had a steep learning curve. If ...
7
votes
1answer
293 views

How to use BDD to unit test a compiler?

My team is writing a compiler for a domain-specific language (DSL) which will be integrated into an IDE. Right now, we are focused on the analysis phase of the compiler. We are not using any existing ...
3
votes
5answers
731 views

Best practice for code coverage of empty interface methods

Given a class that implements an interface, but does not need all of the methods implemented, what is the best practice for unit testing this class with respect to code coverage? - or is it considered ...
4
votes
4answers
412 views

Good unit-testing story for a unit test training [closed]

I have to advise a training on unit testing in my company. I would like to show a striking, real-life example of an unexpected regression not caught by compilation (of course) but detectable with ...
1
vote
3answers
120 views

Unit Test passing conditions as well as failing conditions?

Should unit tests test passing all cases as well as all failing cases? For example, imagine I have a test Widget_CannotActiveWidgetIfStateIsCancelled. And let's say there are 25 possible states. ...
1
vote
2answers
138 views

Understanding unit testing for dynamically changing condition

I was trying to understand how to write unit tests for a few days now. I'm confused with following scenarios in the existing code. In first function the max value changes depending on the object ...
5
votes
3answers
372 views

How should I unit-test a class that relies on having realistic data?

I have a class that encapsulates the results of a scientific measurement. I’m building in unit tests from the beginning, but I don’t have a lot of experience with unit testing and I’m not sure which ...
-2
votes
4answers
179 views

How to use unit testing? [duplicate]

How to use unit testing? There are a lot of frameworks for different languages, which provide functionality of unit testing. There is a lot of information on how to use each of them technically. Just ...
8
votes
3answers
450 views

Doesn't single-assert unit testing break the DRY principle?

Whenever I write unit tests I have always tried to have a single assert per test to make debugging easier when tests fail. However as I follow this rule I feel like I am constantly copying the same ...
3
votes
2answers
270 views

Advise how to write a simple test for this javascript snippet?

I'm trying to start unit testing (not using any testing frameworks) for my javascripts. Here's one example of it. var obj = {}; obj.disableBtn = function ($btn, style) { ...
0
votes
1answer
133 views

Method visibility for testing partial mocks

I'm currently writing unit tests to test behavior of a method and would like to partially mock the methods calling injected properties. For example: public void doSomething() { int complicatedInt ...
4
votes
1answer
481 views

What to test when building websites using CMS?

My job is mainly building websites using CMS such as Drupal, eZPublish or Magento. Most of the work is templating, CRUD and adhering to the specs with this. Occasionally, there is some ...
48
votes
7answers
3k views

Writing Tests for Existing Code

Suppose one had a relatively large program (say 900k SLOC in C#), all commented/documented thoroughly, well organized and working well. The entire code base was written by a single senior developer ...
2
votes
2answers
503 views

Should I bother to write unit test for UI/UX Components?

So I am building an application with Angular and have started to get into UI testing with DalekJS (http://dalekjs.com). As I have been writing these tests I have been thinking to myself, should I ...
2
votes
2answers
394 views

Unit Tests work but there are still bugs?

Brief History I am new to Automated Unit Testing and Mocking objects world; previously we used to do Unit Testing (including Integration Testing and we mistakenly referred that as Unit Testing) ...
7
votes
6answers
2k views

Unit-Tests and databases: At which point do I actually connect to the database?

There are answers to the question on how test classes that connect to a database, e.g. "Should service test classes connect ..." and "Unit testing - Database coupled app". So, in short let's assume ...
2
votes
2answers
273 views

Unit testing and coupling

As a developer I should strive for low coupling between classes. But low coupling doesn't mean "No coupling" so sometimes I have to allow some code flexibility and use "new" inside a domain model. ...
6
votes
4answers
516 views

I have 200k lines of poorly designed code, will units tests or integration tests be more valuable? [duplicate]

I've inherited a lot of poorly designed code; the code has no tests. I am putting tests in place before I attempt a major refactor, but I have run into a problem with my unit tests. The problem is, I ...
3
votes
2answers
157 views

Unit test strategy for layered (or derived) method calls

Forgive the title -- it needs work. I am struggling to find better English to express my issue. Edits encouraged. Example to describe my issue: Checker Method I have an argument checking method ...
0
votes
2answers
382 views

Unit testing in node.js and mocking modules

I'm trying to test this wrapper to request that I made: // lib/http-client.js var app = require('app'), request = require('request'); exports.search = function(searchTerm, next) { var options ...
1
vote
3answers
336 views

Does non-virtual-by-default lead us to composition-over-inheritance?

There are some design guidelines about testable code in “The Art of Unit Testing”. The first one is “Make methods virtual by default”. I’m curious to know your idea about non-virtual-by-default ...
2
votes
1answer
238 views

TDD / one test representing the whole scenario ? or should I split it? [duplicate]

While practicing TDD, I came across this specification: A user should be created with its password hashed, be persisted and an activation token should be returned. Should my first unit test, (aiming ...
2
votes
1answer
925 views

Should we mock entities and value objects when doing DDD?

After reading a few articles about Newable vs Injectable objects and how these concepts relate to DDD's services, entities and value objects, I was left with some doubts about using newables in my ...
0
votes
1answer
300 views

Is it worth writing a unit test for a DTO with the most basic getter/setters? [duplicate]

The advantage is it protects your DTO against future "enhancements" ?
9
votes
5answers
1k views

Do I need unit test if I already have integration test?

If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write ...
1
vote
3answers
225 views

Unit Test - an Enigma? [duplicate]

I am an objective-c/iOS apps developer and I was wondering if I perform Unit Tests on my code, how should I go about it? What is unit test anyway? Ain't I testing a specific part of code while ...
2
votes
6answers
326 views

How to write unit tests for utility programs

I am working on a C# console application that loads the data from a third party and bulk inserts into tables. Basically the code consists of a static method with logging statements. In these ...
46
votes
6answers
4k views

65.000.000.000 tests to run

I was asked about how to run a suite of 65.000.000.000 tests and I wonder if it is normal to have a project with such a huge amount of tests. Have you worked in projects with this characteristic?
5
votes
2answers
364 views

Tools that can catch “fake coverage”?

Hypothetical scenario: codebase is exercised by unit tests run by a TeamCity build-bot, that also uses the built-in dotCover tool to provide coverage metrics. The build will fail if less than X% of ...
3
votes
1answer
152 views

calling test methods within other test methods

To test a method that returns a clone of the object it is called on, i need to re-run the test suite on the newly created object if i am to ensure that full functionality is retained, i found my ...
1
vote
4answers
243 views

Writing unit test only for applications that requires them [closed]

Bit of a rant, but bear with me. People call me purist. I do not code in any way other than TDD. When I try to push TDD as a company policy, the following conversation: company owner: "we'll do TDD ...
7
votes
3answers
613 views

TDD Mock call verification - is it an anti-pattern?

I've been doing TDD for year now, I feel pretty good about it, I love my test suites and all. However I've noticed that lately I've been doing a lot of mock call verification. For example I'd have a ...
2
votes
2answers
146 views

unit testing variable state explicit tests in dynamically typed languages

I have heard that a desirable quality of unit tests is that they test for each scenario independently. I realised whilst writing tests today that when you compare a variable with another value in a ...
6
votes
2answers
522 views

Unit test SHA256 wrapper queries

I have the following SHA256 wrapper. public static string SHA256(string plainText) { StringBuilder sb = new StringBuilder(); SHA256CryptoServiceProvider provider = new ...
2
votes
2answers
1k views

Need help understanding Mocks and Stubs

I'm new to use mocking frameworks and I have a few questions on the things that I am not clear on. I'm using Rhinomocks to generate mock objects in my unit tests. I understand that mocks can be ...
2
votes
2answers
522 views

CppUnit for unit-testing executable files?

I am not sure if anyone has done it. I am trying to do something that is in general, uncommon i.e. unit-testing executable (Windows) or ELFs (Linux). I know that CppUnit provides a good unit testing ...
1
vote
1answer
99 views

How can I test linkable/executable files that require re-hosting or retargeting?

Due to data protection, I cannot discuss fine details of the work itself so apologies PROBLEM CASE Sometimes my software projects require merging/integration with third party (customer or other ...
9
votes
10answers
900 views

Any tools/suggestions on how to refute code coverage quality argument

Now I know people could consider this question duplicate or asked many times, in which case I would appreciate a link to relevant questions with answer to my question. I have been recently in ...