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)

2
votes
2answers
262 views

Why is it not standard to implement abstraction layers for the file system?

I have been taught to access databases through abstraction layers. I was wondering why it is not also standard practice to access the file system through an abstraction layer? It seems to me unit ...
0
votes
1answer
251 views

how to architect this to make it unit testable

I'm currently working on a project where I'm receiving an object via web service (WSDL). The overall process is the following: Receive object -> add/delete/update parts (or all) of it -> and return ...
0
votes
2answers
79 views

Area of testing

I'm trying to understand which part of my code I should to test. I have some code. Below is example of this code, just to understand the idea. Depends of some parametrs I put one or another currency ...
0
votes
1answer
122 views

unit level testing, agile, and refactoring [duplicate]

I'm working on a very agile development system, a small number of people with my doing the vast majority of progaming myself. I've gotten to the testing phase and find myself writing mostly ...
0
votes
1answer
77 views

Test Doubles : Do they go in “source packages” or “test packages”?

I've got a couple of data access objects (DefaultPersonServices.class, DefaultAddressServices.class) which is responsible for various CRUD operations in a database. A few different classes use these ...
3
votes
2answers
230 views

Unit Testing of JavaScript - Are we testing the logic of the code or the behavior against a browser

[Warning]: I am new to the whole unit testing and have been trying to learn as much as possible. I am working on a MS CRM 2011 project and I have been trying to introduce unit testing in my company. ...
1
vote
1answer
921 views

How to create unit/integration tests for my web app?

I am currently developing an Ajax chat application that uses PHP on the back-end. Some of the features it has right now are different types of users (admin/mod/banned), public and private rooms, ...
5
votes
1answer
232 views

How much mocking is “just right?”

I titled the question jokingly because I'm sure that "it depends," but I have some specific questions. Working in software that has many deep layers of dependency, my team has become accustomed using ...
8
votes
3answers
3k views

How can I unit test a class which requires a web service call?

I'm trying to test a class which calls some Hadoop web services. The code is pretty much of the form: method() { ...use Jersey client to create WebResource... ...make request... ...do ...
5
votes
4answers
487 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
228 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
231 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
209 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
1k 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
157 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
1k 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
461 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
197 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 ...
0
votes
2answers
288 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
113 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
277 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
587 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
391 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
118 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
341 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
171 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
416 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
248 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
109 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
415 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 ...
46
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
481 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
381 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) ...
6
votes
6answers
1k 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
241 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
490 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
152 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
1answer
362 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
325 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
225 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 ...
1
vote
1answer
780 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
256 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" ?
8
votes
5answers
879 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
218 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
305 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
351 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 ...