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)

9
votes
4answers
724 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
278 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
566 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
652 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 ...
6
votes
5answers
393 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
285 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
392 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 ...
79
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
307 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
285 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
415 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
528 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 ...
3
votes
2answers
239 views

Reusing Mocks/Stubs as Test Specification

We use mock to ensure that a unit test only runs against the code that should be tested. This prevents that a bug in a module A causes tests of a dependent module B to fail. However, now we also have ...
1
vote
1answer
483 views

scons and python unit tests best practices

I am using scons to build a large project containing a mix of C++ and Python. I would like scons to run Python unit tests either using nose or not. Currently, we have a long list of tests files and ...
4
votes
4answers
397 views

Do large test methods indicate a code smell?

I have a particular method called TranslateValues() (Cyclomatic-Complexity of 5) which I would like to test. The test requires a substantial number of mock objects which take up most of the method; ...
83
votes
18answers
11k views

Are unit tests really that useful? [closed]

I just graduated with a degree in CS and I currently have a job as a Junior .NET Developer (C#, ASP.NET, and web forms). Back when I was still in university, the subject of unit testing did get ...
7
votes
4answers
922 views

How should I test my TEST code?

One of the few things that most software developers agree on is that you shouldn't rely on code to work correctly unless you test it. If you don't test it, it may have hidden bugs that are only ...
12
votes
3answers
3k views

Unit testing C++: What to test?

TL;DR Writing good, useful tests is hard, and has a high cost in C++. Can you experienced developers share your rationale on what and when to test? Long story I used to do test-driven development, ...
70
votes
15answers
5k views

How to motivate co-workers to write unit-tests?

We're working on a large product which has been in production for about 5 years. The codebase is.. erm.. working. Not really well but it is working. New features are thrown into production and tested ...
3
votes
4answers
642 views

When, Where, and How to Unit Test [duplicate]

I'm very familiar with xUnit frameworks and I try to implement unit tests on every project I start. Somewhere along the way, I realize that I'm writing the same tests over and over again, and then I ...
11
votes
5answers
2k views

What is a normal “functional lines of code” to “test lines of code” ratio?

I'm pretty new to TDD approach and my first experiments say that writing 1 line of functional code means writing about 2-3 lines of testing code. So, in case I'm going to write 1000 LOC, the whole ...
3
votes
3answers
2k views

How to make Unit Tests to make sure stored procedure is deleting row from the database?

I'm new to unit testing and I need some help with the following. I have created a small project to help me learn how to make Unit Tests. The functionality for one of the forms in my application ...
2
votes
2answers
1k views

Is this method of writing Unit Tests correct?

I have created a small C# project to help me learn how to write good unit tests. I know that one important rule of unit testing is to test the smallest 'unit' of code possible so that if it fails you ...
17
votes
4answers
1k views

Implementing unit testing at a company that doesn't do it

My company's head of software development just "resigned" (i.e. fired) and we are now looking into improving the development practices at our company. We want to implement unit testing in all ...
1
vote
3answers
518 views

test coverage reality

I am NOT doing test driven development and I write my test classes after the actual code is written. In my current project I have a test coverage (Line coverage) of 70% for 3000 lines of Java code. I ...
7
votes
3answers
508 views

Unit testing time-bound code

I'm currently working on an application that does a lot of time-bound operations. That is, based on long now = System.currentTimeMillis();, and combined with an scheduler, it will calculate periods of ...
10
votes
7answers
2k views

Unit testing multiple conditions in an IF statement

I have a chunk of code that looks something like this: function bool PassesBusinessRules() { bool meetsBusinessRules = false; if (PassesBusinessRule1 && PassesBusinessRule2 ...
2
votes
2answers
356 views

How do you manage your javascript unit tests?

When you are writing JavaScript unit tests, where do you put all the test code? I see two potential approaches: Leave all your test code with your regular web project and explictly don't release ...
5
votes
4answers
624 views

DRY, string, and unit testing

I have a recurring question when writing unit tests for code that involves constant string values. Let's take an example of a method/function that does some processing and returns a string containing ...
15
votes
6answers
491 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 ...
21
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
378 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
516 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
942 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 ...
17
votes
5answers
5k 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
122 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
597 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
643 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
131 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 ...
16
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
8k 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. ...
10
votes
3answers
718 views

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

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
606 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 ...