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)

3
votes
3answers
244 views

Does the “one assertion per test” rule apply for checking initial conditions?

I've been thinking about unit testing best practices and have come across the one assertion per unit test rule. I can see where this idea would help to isolate pieces of complex operations or ...
4
votes
3answers
482 views

Should unit test be in separated repository?

Should I put unit testing stuffs in a separate repository, not in the same repository as the programming library? So I reference the programming library as submodule. But most open source projects ...
15
votes
5answers
2k views

What is considered third party code?

Inspired by this question Using third-party libraries - always use a wrapper? I wanted to know what people actually consider as third-party libraries. Example from PHP: If I'm building an application ...
5
votes
1answer
660 views

Is wrapping a third party code the only solution to unit test its consumers?

I'm doing unit testing and in one of my classes I need to send a mail from one of the methods, so using constructor injection I inject an instance of Zend_Mail class which is in Zend framework. Now ...
1
vote
2answers
399 views

NUnit SetUp and TearDown

I have some experience in MS Test but new to NUnit. Whether NUnit [Setup] is corresponding to [ClassInitialize] or [TestInitialize] in MS Test? What is the NUnit attribute corresponding to ...
26
votes
1answer
904 views

How have Guava unit tests been generated automatically?

Guava has unit test cases automatically generated: Guava has staggering numbers of unit tests: as of July 2012, the guava-tests package includes over 286,000 individual test cases. Most of ...
5
votes
3answers
2k views

Where should I draw the line between unit tests and integration tests? Should they be separate?

I have a small MVC framework I've been working on. It's code base definitely isn't big, but it's not longer just a couple of classes. I finally decided to take the plunge and start writing tests for ...
0
votes
4answers
338 views

Is it dangerous to substitute unit tests for user testing? [closed]

Is it dangerous to substitute unit tests for user testing? A co-worker believes we can reduce the manual user testing we need to do by adding more unit tests. Is this dangerous? Unit tests seem to ...
4
votes
4answers
341 views

Are injectable classes allowed to have constructor parameters in DI?

Given the following code: class ClientClass{ public function print(){ //some code to calculate $inputString $parser= new Parser($inputString); $result= ...
21
votes
5answers
2k views

Do unit tests sometimes break encapsulation? [duplicate]

I very often hear the following: "If you want to test private methods, you'd better put that in another class and expose it." While sometimes that's the case and we have a hiding concept inside our ...
11
votes
4answers
339 views

What are best practices for testing programs with stochastic behavior?

Doing R&D work, I often find myself writing programs that have some large degree of randomness in their behavior. For example, when I work in Genetic Programming, I often write programs that ...
4
votes
6answers
449 views

Pair programming and unit testing

My team follows the Scrum development cycle. We have received feedback that our unit testing coverage is not very good. A team member is suggesting the addition of an external testing team to assist ...
2
votes
3answers
361 views

What does well written, readable tests look like? [closed]

Doing unit testing for the first time at a large scale, I find myself writing a lot of repetitive unit tests for my business logic. Sure, to create complete test suites I need to test all ...
2
votes
2answers
224 views

Returning a mock object from a mock object

I'm trying to return an object when mocking a parser class. This is the test code using PHPUnit 3.7 //set up the result object that I want to be returned from the call to parse method ...
7
votes
3answers
894 views

How important are unit tests in software development? [closed]

We are doing software testing by testing a lot of I/O cases, so developers and system analysts can open reviews and test for their committed code within a given time period (e.g. 1 week). But when ...
4
votes
4answers
178 views

How to implement isValid correctly?

I'm trying to provide a mechanism for validating my object like this: class SomeObject { private $_inputString; private $_errors=array(); public function __construct($inputString) { ...
7
votes
6answers
938 views

Should we exclude code for the code coverage analysis?

I'm working on several applications, mainly legacy ones. Currently, their code coverage is quite low: generally between 10 and 50%. Since several weeks, we have recurrent discussions with the ...
3
votes
1answer
2k views

Using Mock for event listeners in unit-testing

I keep getting to test this kind of code (language irrelevant) : public class Foo() { public Foo(IDependency1 dep1) { this.dep1 = dep1; } public void setUpListeners() { ...
6
votes
4answers
459 views

Achieving decoupling in Model classes

I am trying to test-drive (or at least write unit tests) my Model classes but I noticed that my classes end up being too coupled. Since I can't break this coupling, writing unit tests is becoming ...
1
vote
3answers
494 views

unit/integration testing web service proxy client

I'm rewriting a PHP client/proxy library that provides an interface to a SOAP-based .Net webservice, and in the process I want to add some unit and integration tests so future modifications are less ...
3
votes
5answers
715 views

“TDD is about design, not verification”; concretely, what does that mean?

I've been wondering about this. What do we exactly mean by design and verification. Should I just apply TDD to make sure my code is SOLID and not check if it's external behaviour is correct? Should ...
6
votes
1answer
155 views

Unit testing a text index

Consider a text index such as a suffix tree or a suffix array supporting Count queries (number of occurrences of a pattern) and Locate queries (the positions of all the occurrences of a pattern) over ...
6
votes
7answers
1k views

Is mocking for unit testing appropriate in this scenario?

I have written around 20 methods in Java and all of them call some web services. None of these web services are available yet. To carry on with the server side coding, I hard-coded the results that ...
0
votes
3answers
412 views

Introduce unit testing when codebase is already available [duplicate]

Possible Duplicate: Best practices for retrofitting legacy code with automated tests I've been working on a project in Flex for three years now without unit testing. The simple reason for ...
3
votes
1answer
1k views

How to unit test image processing code?

I'm working in image processing (mainly OCR) and I wonder how I should integrate unit tests in my development. I'm already using unit tests for more "common" type of code but when dealing with image ...
23
votes
4answers
3k views

TDD - Outside In vs Inside Out

What is the difference between building an application Outside In vs building it Inside Out using TDD? These are the books I read about TDD and unit testing: Test Driven Development: By Example ...
7
votes
4answers
734 views

Unit testing and Test Driven Development questions

I'm working on an ASP.NET MVC website which performs relatively complex calculations as one of its functions. This functionality was developed some time ago (before I started working on the ...
0
votes
3answers
361 views

What's wrong performing unit test against concrete implementation if your frameworks are not going to change?

First a bit of background: We are re-architecting our product suite that was written 10 years ago and served its purpose. One thing that we cannot change is the database schema as we have 500+ client ...
2
votes
3answers
575 views

TDD, BDD or both? [duplicate]

I'm a little bit confused about BDD. I'm doing TDD currently. My question is whether BDD is complementary to TDD or it's a whole new thing and my team should do both TDD and BDD? Or is it enough to ...
2
votes
5answers
538 views

Resurrecting a 5,000 line test plan that is a decade old

I am currently building a test plan for the system I am working on. The plan is 5,000 lines long and about 10 years old. The structure is like this: 1. test title precondition: some W needs to ...
2
votes
2answers
574 views

Which Continuous Integration for Selenium 2 with TestNG

So I have a Selenium Automation project (using Maven). I'd like to be able to set my tests to run overnight and possibly email a report daily to the team. Which CI would be most suitable for ...
3
votes
3answers
648 views

iOS - Unit tests for KVO/delegate codes

I am going to design a MVC pattern. It could be either designed as a delegate pattern, or a Key-Value-Observing(KVO), to notify the controller about changing models. The project requires certain ...
3
votes
3answers
854 views

How do I make code bound to an ORM testable?

In Test Driven Development, how do I make code bound to an ORM testable? I am using a Micro-ORM (PetaPoco) and I have several methods that interact with the database like: AddCustomer UpdateRecord ...
9
votes
4answers
798 views

How to unit test a function that is refactored to strategy pattern?

If I have a function in my code that goes like: class Employee{ public string calculateTax(string name, int salary) { switch (name) { case "Chris": ...
7
votes
1answer
287 views

Who should initialize dependencies in a TDD application?

I'm trying to learn implementing TDD with mocking/fake objects. One of the questions I have is how to initialize a dependency in an application which implements TDD? An example from this article ...
4
votes
1answer
1k views

Linux OS developers : do they unit test their code? [closed]

Linux OS developers : do they unit test their code ? If yes : since this OS is coded in C, how do they manage to write effectively unit tests in this language ? what are the "zones" in OS where ...
7
votes
5answers
582 views

Is it typical for a unit test suite to be larger than the code it tests? [duplicate]

Possible Duplicate: What is a normal “functional lines of code” to “test lines of code” ratio? I've found that more often than not, when you write lots of unit ...
0
votes
4answers
462 views

What Are Some Tips For Writing A Large Number of Unit Tests? [closed]

I've recently been tasked with testing some COM objects of the desktop app I work on. What this means in practice is writing a large number (>100) unit tests to test different but related methods and ...
9
votes
2answers
675 views

Unit Testing: “It's a code smell if you're refactoring and there are no collaborators”?

I'm reading The Art of Unit Testing by Roy Osherove. I'm at section 7.2 Writing maintainable tests where the author has this note about code smell: NOTE: When you refactor internal state to be ...
7
votes
5answers
397 views

Can unit testing software be used to unit test itself?

QUnit advertises itself on its web page like this: ...capable of testing any generic JavaScript code, including itself! Can you really use unit testing software to test itself? Wouldn't defects ...
2
votes
4answers
294 views

Standards of unit testing output

Simple question, what's more common / standard / won't make future developers look at me cross-eyed for unit testing: Displaying just the errors, or reporting every passed test?
1
vote
2answers
416 views

Unit Tests code duplication?

How can I avoid code duplication in unit tests? Using Java and JUnit suppose I have something like this: public interface Arithmetic<T> { public T add(T a, T b); public T sub(T a, T ...
81
votes
12answers
6k views

How big does my project need to be for me to unit test it? [closed]

I assume that my project is decoupled enough to allow for unit testing. But how big, exactly, in terms of clases and functions does my project need to be to make unit testing worthwhile? We all make ...
2
votes
2answers
1k views

Testing my VB.NET code?

I'm having trouble developing unit testing approaches to testing both if the "code does what I want it to do", and testing "does my code work". For example, I'm writing code to validate input that ...
4
votes
4answers
308 views

What level do I mock when I have function A calling function B which calls the database?

I have created a scenario in which I have two functions, A and B, both are tested, but despite the tests I still injected a rather stupid bug and some data is not getting into the database. Note that ...
9
votes
9answers
1k views

As a professional developer, is it acceptable to not write unit tests? [closed]

Just wondering on the pros and cons on TDD/automated unit testing and looking for the community's view on whether it's acceptable for professional developers to write applications without supporting ...
3
votes
3answers
1k views

Writing Unit Tests for a Class That Starts External EXE

I wrote a C# class that is used to start a list of EXEs (not one of mine - third party EXEs I have to run) and keep them running (will check occasionally to make sure it is still running, and start ...
1
vote
1answer
296 views

How best to enable a web service consumer to integration test a transactional web service?

I want to allow consumers of a web services layer (web services are written in Java) to create automated integration tests to validate that the version of the web services layer that the consumers ...
5
votes
6answers
420 views

Sporadic unittests or TDD?

I've read some basics about unit tests and TDD, but I find it hard to convince myself why TDD can have an advantage over only selected unittests. I've read common arguments for TDD, but don't see the ...
7
votes
4answers
553 views

Do some best practices depend on skill?

Is there evidence that some software development best practices depend on programming skill level? I mean, these methods are good, but maybe the way the are used or the extent might vary? This ...