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)

15
votes
6answers
512 views

Are unit tests really used as documentation?

I cannot count the number of times I read statements in the vein of 'unit tests are a very important source of documentation of the code under test'. I do not deny they are true. But personally I ...
5
votes
2answers
3k views

How do you handle measuring Code Coverage in JavaScript

In order to measure Code Coverage for JavaScript unit tests, one needs to instrument the code, run the tests and then perform post-processing. My concern is that, as a result, you are unit testing ...
22
votes
7answers
1k views

Quality of Code in unit tests?

When writing unit tests, is it worth spending the extra time to make the code have good quality and readability? When writing tests I often break the Law of Demeter, for faster writing and to avoid ...
23
votes
17answers
2k views

Should I demand unit-testing from programmers? [closed]

I work at a place where we buy a lot of IT projects. We are currently producing a standard for systems-requirements for the requisition of future projects. In that process, we are discussing whether ...
2
votes
2answers
424 views

How do functional languages handle a mocking situation when using Interface based design?

Typically in C# I use dependency injection to help with mocking; public void UserService { public UserService(IUserQuery userQuery, IUserCommunicator userCommunicator, IUserValidator userValidator) ...
3
votes
1answer
709 views

How to define implementation details?

In our project, an assembly combines logic for the IoC-Container, the project internals and the communication layer. The current version evolved to have only internal classes in addin assemblies. My ...
26
votes
6answers
963 views

Unit and Integration testing: How can it become a reflex

All the programmers in my team are familiar with unit testing and integration testing. We have all worked with it. We have all written tests with it. Some of us even have felt an improved sense of ...
19
votes
5answers
6k 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 ...
1
vote
1answer
147 views

When writing tests for a Wordpress plugin, should i run them inside wordpress or in a normal browser?

I have started using BDD for a wordpress plugin i'm working on and i'm rewriting the js codebase to do tests. I've encountered a few problems but i'm going steady now, i was wondering if i had the ...
8
votes
2answers
772 views

All unit tests in one executable, or split them up?

When writing tests for one piece of software, say a library, do you prefer to compile all unit tests into one, or separate them into several executables? The reason I'm asking is because I am ...
5
votes
5answers
723 views

How does one unit test an algorithm

I was recently working on a JS slideshow which rotates images using a weighted average algorithm. Thankfully, timgilbert has written a weighted list script which implements the exact algorithm I ...
2
votes
2answers
136 views

Assignments in mock return values

(I will show examples using php and phpunit but this may be applied to any programming language) The case: let's say we have a method A::foo that delegates some work to class M and returns the value ...
22
votes
9answers
1k views

Is unit testing development or testing?

I had a discussion with a testing manager about the role of unit and integration testing. She requested that developers report what they have unit and integration tested and how. My perspective is ...
3
votes
5answers
10k views

How to unit test a jsp file?

I'm developing a Java 6 EE application and I'm testing my jsp code with another one with a testing version of the function calls and code used in the original one but it seems loose and impractical. ...
13
votes
3answers
1k views

How would you unit-test or perform the most effective automated testing on graphics code for OpenGL?

I'm writing a game and the accompanying graphics engine on top of OpenGL in C++. Im also a fan of good coding processes and automated testing. Graphics code + testing seems pretty immiscible, since ...
7
votes
3answers
712 views

Interfacing application code with unit tests

I am working on a project in which we have to implement and unit test some new module. I had a quite clear architecture in mind so I quickly wrote down the main classes and methods and then we started ...
5
votes
1answer
762 views

How to unit test large legacy systems? [duplicate]

Possible Duplicate: Best practices for retrofitting legacy code with automated tests When working in large legacy systems (large systems with no unit testing ever) I often come across ...
9
votes
5answers
2k views

Is unit testing procedural code effective?

On a current project, the powers that be want to have unit testing incorporated into our development cycle to avoid the constant amount of bugs that seem to seep into our code. The problem is that the ...
3
votes
4answers
793 views

Testing thread safety

Say you have a function f that is or contains a critical section. How would you unit test that only one thread can run it at once, that it doesn't have race conditions, and that it doesn't cause a ...
8
votes
6answers
517 views

How to use unit tests as a source of information?

A colleague of mine was once at a seminar about agile development, where he heard it is possible to use unit tests as technical documentation. Something like using unit tests as an example of how to ...
1
vote
2answers
73 views

Should Multiple Data Items be in Multi Unit Test Methods?

I often want to have the same unit test applied to data multiple items that are roughly equivalent (two non-empty strings). Currently I implement these in multiple unit test methods, with names like ...
2
votes
4answers
204 views

Testing a file that relies heavily on a static array

I have a .c file that basically manages its own little database of people. There are add, remove, edit and search functions among some others. It has a static array which it uses to store the data. ...
1
vote
2answers
513 views

Looking for good testing in multithreaded C or C++ open source projects [closed]

I have read a lot about the importance of unit testing, and testing in general. In particular I have read about TDD which, in theory, seems like a good way to ensure effective test coverage for a ...
47
votes
10answers
7k 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 ...
10
votes
5answers
2k views

switch statement - handling default case when it can't be reached

If I'm using a switch statement to handle values from an enum (which is owned by my class) and I have a case for each possible value - is it worth adding code to handle the "default" case? enum ...
4
votes
4answers
344 views

Unit testing: about easy- and hard-first strategies

I've never written a unit test. I'm reading The art of Unit Testing by Osherove, and he explains a way to choose where to start when you're writing tests for legacy code. Basically you end up with ...
67
votes
16answers
10k views

When is unit testing inappropriate or unnecessary? [duplicate]

It seems to be generally assumed (on Stack Overflow at least) that there should always be unit tests, and they should be kept up to date. But I suspect the programmers making these assertions ...
6
votes
6answers
2k views

Can the Strategy pattern be implemented without significant branching?

The Strategy pattern works well to avoid huge if...else constructs and make it easier to add or replace functionality. However, it still leaves one flaw in my opinion. It seems like in every ...
4
votes
1answer
655 views

What and how to unit test a django web application?

I am writing unit tests for a web frontend implemented in Django. I have written unit tests that check that all views return the correct status code (200, 302 etc) so that template errors (which give ...
17
votes
4answers
691 views

How do I write unit tests for robots (and other mechanical devices)?

I'm a member of my high school's robotics club, and am responsible for programming the robot. One suggestion I keep hearing from various adults is that I should be writing unit tests to help validate ...
2
votes
1answer
322 views

Virtual Machines And Unit/Integration Testing Web Application

I am in the process of adding unit testing to a project I am working on at work and a suggestion came up that I should use VMs to populate the database with good data. This was suggested as an ...
15
votes
3answers
3k views

Real-world examples of apps written with TDD and good test coverage? [closed]

Are there any open source applications that are developed using test driven development that serve as models of how good unit testing should work? I'd prefer to see examples in C# and .NET. (Note ...
0
votes
3answers
375 views

Is Debug.Assert obsolete if you write unit tests?

Just like the question asks, is there a need to add Debug.Assert into your code if you are writing unit tests (which has its own assertions)? I could see that this might make the code more obvious ...
4
votes
8answers
494 views

Testing loses its effectiveness if all programmers don't use them

Let's assume you are convinced that the extra time spent unit testing has merit and improves production. Does that still hold up when everyone working on the same code doesn't use them? This question ...
0
votes
1answer
78 views

Compatibility Test and other testing method to use while building software

I will be adding a feature to the software and have to update or modify some of public API of the present open source software. What are steps which could be taken to ensure the compatibility of the ...
2
votes
3answers
483 views

Development processes, the use of version control, and unit-testing [closed]

Preface I've worked at quite a few "flat" organizations in my time. Most of the version control policy/process has been "only commit after it's been tested". We were constantly committing at each ...
5
votes
2answers
190 views

CI tests to enforce specific development rules - good practice?

The following is all purely hypothetical and any particular portion of it may or may not accurately describe real persons or situations, whether living, dead or just pretending. Let's say I'm a ...
0
votes
2answers
2k views

Should I use a seperate class per test?

Taking the following simple method, how would you suggest I write a unit test for it (I am using MSTest however concepts are similar in other tools). public void MyMethod(MyObject myObj, bool ...
48
votes
16answers
3k views

Why not write all tests at once when doing TDD?

The Red - Green - Refactor cycle for TDD is well established and accepted. We write one failing unit test and make it pass as simply as possible. What are the benefits to this approach over writing ...
4
votes
2answers
910 views

How and what should I be (unit) testing for in this method?

I am relatively new to unit testing and have a query about what/how I should be testing a certain method. For the following (psudo-c#) method I have created (not a real-life example) what would you ...
0
votes
1answer
699 views

Differences between software testing processes and techniques?

I get confused between these terms. For example, should unit testing be listed as a software testing process or technique? I think unit testing is a software testing technique. And how about Test ...
1
vote
4answers
335 views

Is application-specific data required for good unit testing?

I am writing unit tests for a fairly simple function that depends on a fairly complicated set of data. Essentially, the object I am manipulating represents a graph and this function determines whether ...
11
votes
3answers
1k views

What arguments can I use to “sell” the BDD concept to a team reluctant to adopt it?

I am a bit of a vocal proponent of the Behaviour Driven Development methodology (aka BDD). I've been applying BDD for a couple of years now, and have adopted StoryQ as my framework of choice when ...
29
votes
7answers
6k views

Is dependency injection essential for unit testing?

Is using dependency injection (DI) essential for unit testing? I can't think of another alternative for isolating code so it can be tested. Also, all the examples I have ever seen use this pattern. ...
0
votes
1answer
3k views

Implementing a ILogger interface to log data

I have a need to write data to file in one of my classes. Obviously I will pass an interface into my class to decouple it. I was thinking this interface will be used for testing and also in other ...
2
votes
5answers
1k 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 ...
8
votes
5answers
746 views

Is it OK to repeat code for unit tests?

I wrote some sorting algorithms for a class assignment and I also wrote a few tests to make sure the algorithms were implemented correctly. My tests are only like 10 lines long and there are 3 of ...
3
votes
2answers
1k views

How much extra time is needed to add unit test in a development task?

My team is considering moving to test-driven development. Currently we have almost no unit testing, we have been only relying on the user acceptance test, and developer's own manual test. Not everyone ...
34
votes
10answers
4k views

Is unit testing or test-driven development worthwhile?

My team at work is moving to Scrum and other teams are starting to do test-driven development using unit tests and user acceptance tests. I like the UATs, but I'm not sold on unit testing for ...
1
vote
2answers
2k views

Is there a good example of Python code for unit testing an api? [closed]

Do you know any good example of Python unit testing code for testing an API? Thanks! Update: Found this very interesting question: ...