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
2answers
458 views

When to write Unit Tests : Is there any or list of terms to take right decision [closed]

To write Unit Tests we have to write extra bits of code. For several projects we do Unit Tests and for several projects we do not. As a Team Leader I face trouble to make the right decision. Is ...
6
votes
2answers
2k views

Helper static methods in TDD

I am creating an application which will be testable(unit + integration). In this application I have a FileHelper static class, public static class FileHelper { public static void ...
5
votes
2answers
412 views

Write tests for unit tests in TDD?

In an answer to another question, I suggested creating a randomized value for input to a specific method. In my experience this has been useful for making tests more readable and it lets you skip the ...
5
votes
2answers
8k views

JUnit Testing in Multithread Application

This is a problem me and my team faces in almost all of the projects. Testing certain parts of the application with JUnit is not easy and you need to start early and to stick to it, but that's not the ...
5
votes
5answers
4k views

Is path coverage stronger than condition coverage?

I have encountered (even in literature) two contradicting opinions related to path vs condition coverage (not branch or edge!). Some say Path coverage is stronger than the condition coverage, some say ...
155
votes
16answers
15k views

Why does automated testing keep failing in my company?

We have tried to introduce developer automated testing several times at my company. Our QA team uses Selenium to automate UI tests, but I always wanted to introduce unit tests and integration tests. ...
31
votes
6answers
3k views

How should you TDD a Yahtzee game?

Let's say you're writing a Yahtzee game TDD style. You want to test the part of the code that determines whether or not a set of five die rolls is a full house. As far as I know, when doing TDD, you ...
5
votes
7answers
441 views

Test driven development when implementing a flexible length list

According to the commonly used TDD strategy, to implement something, you write a test that fail the code first, write the simplest code, refactor, and then repeat. I am trying to imagine this scenario ...
12
votes
2answers
661 views

How do I know if I have enough unit test coverage to remove an integration test?

I'm working on a legacy system (by that I mean it was written without tests). We've tried to test some of the system by writing integration tests that test functionality from the outside. This ...
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 ...
6
votes
2answers
1k views

Unit Test Friendly Domain Driven Design

Many of the readings I've done on DDD, both in books and online, seem to represent code that, often times, is difficult or impossible to unit test. For example, there are numerous samples with static ...
3
votes
3answers
423 views

Is unconditional code considered a branch?

Having simple code like this: int A=5; object X=Console.ReadLine() if(Condition) DoSomething(); else DoStuff(); DoSomethingElse(); Some sources say there are actually 4 branches: First ...
2
votes
1answer
302 views

Specifying Query in Unit Test

When writing unit tests, should I specify the query that will be performed for interacting with the database? I can see both sides of this. On one hand, I want to make sure that the query that I ...
11
votes
6answers
3k views

Best practices for unit testing methods that use cache heavily?

I have a number of business logic methods that store and retrieve (with filtering) objects and lists of objects from cache. Consider IList<TObject> AllFromCache() { ... } TObject ...
2
votes
1answer
217 views

Unit Testing Open Source projects that require keys for api calls

What's the recommended method for setting up tests on code that requires a private key to make calls to external web services? Full on mock objects or is there a way of distributing open source unit ...
28
votes
11answers
7k views

How do we make unit tests run fast?

We have reached the point in our project where we have almost a thousand tests and people have stopped bothering with running them before doing a check in because it takes so long. At best they run ...
11
votes
3answers
644 views

Is using unit tests to tell a story a good idea?

So, I have an authentication module I wrote some time ago. Now I'm seeing the errors of my way and writing unit tests for it. While writing unit tests, I have a hard time coming up with good names and ...
4
votes
2answers
128 views

Unit testing markup building logic

I'm currently writing a library of helper functions to produce some repetitive markup. I have a reference to the markup the functions should produce, but I'm curious about how I should go about unit ...
5
votes
2answers
301 views

Is it ok to use static (compile-time) assertions in unit tests?

Or more generally: to trigger compiler errors in test projects if something that can be checked at compile time is wrong?
4
votes
7answers
454 views

Should I spend time prettifying unit tests? [closed]

The company I used to work for before we had automated unit tests to test our work. However the coding standards and architecture was not very important for tests. Of course you had to indent code ...
5
votes
3answers
527 views

How much to test in TDD?

I am newbie to TDD (writing first project following TDD practices). I have fairly basic interface IProfiler and an implementation Profiler. interface IProfiler { bool IsBusy {get;} long Elapsed ...
27
votes
5answers
4k views

Why is it often said that the test cases need to be made before we start coding? [duplicate]

Why is it often said that the test cases need to be made before we start coding? What are its pros and what the cons if we don't listen to this advice? Moreover, does that advice refer to black box ...
20
votes
3answers
6k views

Should I still use Debug.Assert today?

I recently came across some newly written code that was interspersed with lots of Debug.Assert (C#). Should we still use this widely despite the usage of TDD, BDD and Unit Testing in general?
3
votes
1answer
684 views

How to structure unit testing of huge libraries?

I am writing unit tests for a library written in Qt/C++. The library is rather big, with lots of functionalities. I have a separate unitTest folder which I have my UnitTest.cpp in there. Having all ...
5
votes
4answers
3k views

Behavior Driven Development and Unit Testing in Python [closed]

We might be interested in starting to incorporate a unit test suite to our project, which is coded in Python (and it uses Redis, PostgreSQL and some third-party libraries, if that bears into the ...
6
votes
2answers
581 views

Unit Testing and Asserting

Assume we have a method that validates an object before saving it to a DB. It returns back KVP something like: public KeyValuePair<bool, List<FooErrorReason>> ValidateABar(Bar b) { ...
10
votes
2answers
294 views

How would type errors be detected while creating mocks in a dynamic language?

The problem occurs while doing TDD. After a couple of test pass, the return types of some class/module change. In a statically typed programming language, if a previous mocked object was used in the ...
3
votes
1answer
513 views

TDD and test automation in applications heavily dependent on databases and user input [closed]

Recently I have been reading online about eXtreme programming and agile practices. I wish to adapt them. However most of my code is all in PHP which is the normal CRUD type web applications. Moreover ...
7
votes
3answers
1k views

Unit Testing DatabaseOpenHelper class in Android

I've written several unit tests for an already existing DatabaseOpenHelper class. I covered the creation scenario and migration from old schema to new one. Unfortunately, I don't feel that my tests ...
10
votes
5answers
781 views

Is adhering to one assert per test foolish consistency in this case?

I have a class that I'm testing. The class has a function: apply(List<IRule> rules, List<ITarget> targets); In one test I want to ensure that each target has been passed to one rule, a ...
6
votes
1answer
111 views

Is there ever a reasonable time to have test fixtures test MVC3 controller construction?

I've recently started with a new firm and I'm trying to understand the mechanics behind something, so I'll anonymize the code and present but a sample: [Test(Description = "Retreives the New view for ...
8
votes
5answers
448 views

What are tangible advantages to proper Unit Tests over Functional Test called unit tests

A project I am working on has a bunch of legacy tests that were not properly mocked out. Because of this the only dependency it has is EasyMock, which doesn't support statics, constructors with ...
2
votes
1answer
194 views

Link between tests and user stories

I have not see these links explicitly stated in the Agile literature I have read. So, I was wondering if this approach was correct: Let a story be defined as "In order to [RESULT], [ROLE] needs to ...
4
votes
1answer
212 views

Using NSpec at various architectural layers

Having read the quick start at nspec.org, I realized that NSpec might be a useful tool in a scenario which was becoming a bit cumbersome with NUnit alone. I'm adding an OAuth (or, DotNetOpenAuth) to ...
5
votes
2answers
8k views

Does Visual Studio 2012 Express support NUnit tests? [closed]

I am currently using Visual Studio Express 2012 Desktop (the free version). I now have received source code with NUnit tests included. I can not bring them to run with Visual Studio (not seeing them ...
8
votes
4answers
874 views

Is it useful to unit test methods where the only logic is guards?

Say I have a method like this: public void OrderNewWidget(Widget widget) { if ((widget.PartNumber > 0) && (widget.PartAvailable)) { ...
2
votes
2answers
320 views

Unit test and Code Coverage of Ant build scripts

In our development environment We have more and more build scripts for ant to perform the build tasks for several different build jobs. These build scripts sometimes become large and do a lot of ...
13
votes
4answers
1k views

If you should only have one assertion per test; how to test multiple inputs?

I'm trying to build up some test cases, and have read that you should try and limit the number of assertions per test case. So my question is, what is the best way to go about testing a function w/ ...
9
votes
3answers
1k views

Mocking concrete class - Not recommended

I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended. Here some sample code of a unit-test for the ...
4
votes
3answers
540 views

Should adapters or wrappers be unit tested?

Suppose that I have a class that implements some logic: public MyLogicImpl implements MyLogic { public void myLogicMethod() { //my logic here } } and somewhere else a test class: ...
8
votes
5answers
618 views

How to TDD test that objects are being added to a collection if the collection is private?

Assume that I planned to write a class that worked something like this: public class GameCharacter { private Collection<CharacterEffect> _collection; public void Add(CharacterEffect e) ...
-2
votes
2answers
622 views

How can I test database access methods in Java? [closed]

I want to write a test for a method that accesses a database such as following. public class MyClass{ public String getAddress(Int id){ String query = "Select * from Address where ...
1
vote
1answer
305 views

Unit test: How best to provide an XML input?

I need to write a unit test which validates the serialization of two attributes of an XML(size ~ 30 KB) file. What is the best way to provide an input for this test? Here are the options I have ...
0
votes
1answer
330 views

Control flow testing in white box - static or dynamic?

Yesterday I asked a question that happened to have another meaning inside. I can see that Control/data flow is often mentioned to be static analysis (when tools is used) or dynamic analysis testing in ...
4
votes
4answers
773 views

What if I can't make my unit test fail in “Red, Green, Refactor” of TDD?

So let's say that I have a test: @Test public void MoveY_MoveZero_DoesNotMove() { Point p = new Point(50.0, 50.0); p.MoveY(0.0); Assert.assertAreEqual(50.0, p.Y); } This test then ...
10
votes
4answers
430 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 ...
3
votes
3answers
263 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
587 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
3k 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 ...
7
votes
1answer
1k 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 ...