Questions tagged [unit-testing]
Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
1,726
questions
38
votes
13
answers
6k
views
Writing the minimum code to pass a unit test - without cheating!
When doing TDD and writing a unit test, how does one resist the urge to "cheat" when writing the first iteration of "implementation" code that you're testing?
For example:
Let's I need to calculate ...
63
votes
9
answers
23k
views
How to write "good" unit tests?
Triggered by this thread, I (again) am thinking about finally using unit tests in my projects. A few posters there say something like "Tests are cool, if they are good tests". My question now: What ...
58
votes
3
answers
15k
views
Are asserts or unit tests more important?
Both asserts and unit tests serve as documentation for a codebase, and a means of discovering bugs. The main differences are that asserts function as sanity checks and see real inputs, whereas unit ...
11
votes
3
answers
2k
views
Is it a good idea to do TDD on low level components?
I'm considering writing a low level driver or OS components/kernels.
The osdev.org folks seem to think that the important bits are not meaningfully testable this way, but I have read some discussions ...
14
votes
4
answers
2k
views
Unit testing internal components
To what extent do you unit test internal/private components of a class/module/package/etc? Do you test them at all or do you just test the interface to the outside world? An example of these internal ...
22
votes
6
answers
10k
views
Unit test coding standards
Usually when talking about coding standards we refer to the code of the program itself, but what about the unit tests? Are there certain coding standards guidelines that are unique to unit tests? What ...
12
votes
1
answer
2k
views
How would I unit test database logic?
I am still having a issue getting over a small issue when it comes to TDD.
I need a method that will get a certain record set of filtered data from the data layer (linq2SQL). Please note that i am ...
5
votes
2
answers
1k
views
Good example of a properly unit tested PHP project? [closed]
In hopes of getting myself and my coworkers to adopt automated unit testing methods in future projects, I would like to see a proper example on how it's done. Simple introductionary lessons to unit ...
7
votes
3
answers
5k
views
What is the best practice for refactoring a static method in order to make it more testable?
Let's say you have a static method that looks something like this:
public static bool Foo()
{
var bar = new Bar();
//do some stuff here
}
This method as it stands can be a real headache to ...
11
votes
3
answers
247
views
Unit tests, write them before or after the framework? [closed]
This is my first question here, so i'll make it short and to the point.
When Writing unit tests, should you write them before or after you have made the underlying framework for them? This came up in ...
27
votes
5
answers
4k
views
I want to start using TDD. Any tips for a beginner? [closed]
I never used an automated test mechanism in any of my projects and I feel I'm missing a lot. I want to improve myself, so I have to start tackling some issues I've been neglecting like this and trying ...
57
votes
10
answers
5k
views
How to test the tests?
We test our code to make it more correct (actually, less likely to be incorrect). However, the tests are also code -- they can also contain errors. And if your tests are buggy, they hardly make your ...
3
votes
2
answers
749
views
Is testing the easiest way to contribute to an Open Source Project?
I want to contribute to an open source project, but I don't know much about unit testing. I want to learn how to test and then practice my skills on an open source.
Will this also be acknowledged as ...
38
votes
7
answers
3k
views
Unit testing newbie team needs to unit test
I'm working with a new team that has historically not done ANY unit testing. My goal is for the team to eventually employ TDD (Test Driven Development) as their natural process. But since TDD is ...
21
votes
7
answers
13k
views
Best book, articles and literature on unit testing [closed]
In my battle to introduce unit testing in my workgroup, I find a lot of people that have little to none knowledge of the concept. Can you suggest:
best articles or tutorials for quickly introducing ...
15
votes
7
answers
1k
views
How can I advocate unit testing on private code?
I'm trying to advocate unit testing in my workgroup, but an objection I often get is that it should be used only for externally exported API (which is only a minimal and non critical part of our ...
35
votes
8
answers
21k
views
How do I unit test multi-threaded code? [duplicate]
Are there ways to unit test your multi-threaded code for race conditions and deadlocks?
To see if they are performing the way they should be...
528
votes
18
answers
450k
views
Is it OK to have multiple asserts in a single unit test?
In the comment to this great post, Roy Osherove mentioned the OAPT project that is designed to run each assert in a single test.
The following is written on the project's home page:
Proper unit ...
7
votes
6
answers
3k
views
What unit test frameworks exist for Java?
I've used TestNG and JUnit. What other frameworks are out there? What makes them special and/or different from the rest?
92
votes
11
answers
84k
views
Is static universally "evil" for unit testing and if so why does Resharper recommend it? [closed]
I have found that there are only 3 ways to unit test (mock/stub) dependencies that are static in C#.NET:
Moles
TypeMock
JustMock
Given that two of these are not free and one has not hit release 1.0, ...
19
votes
1
answer
14k
views
How to set up Unit Testing in Visual Studio 2010? [closed]
I'm doing my first big project and I don't have a lot of experience in a professional programming environment. While researching anything programming-related I often see references to Unit Testing, ...
23
votes
16
answers
11k
views
Who does test-driven development?
I've been working in the enterprise space for the past 4½ years and have noticed that generally speaking, enterprises are not conducive environments for the test-first style of development. Projects ...
19
votes
9
answers
3k
views
How have you made unit testing more enjoyable? [closed]
If you've always loved unit testing, good for you! But for the unfortunate ones who weren't born with a liking for it, how have you managed to make this task more enjoyable ?
This is not a "what is ...
40
votes
12
answers
24k
views
How much Code Coverage is "enough"?
We are starting a push for code coverage here at my work, and it has got me to thinking.... How much code coverage is enough?
When do you get to the point of diminishing returns on code coverage? ...
139
votes
7
answers
58k
views
What should you test with unit tests?
I'm freshly out of college, and starting university somewhere next week. We've seen unit tests, but we kinda not used them much; and everyone talks about them, so I figured maybe I should do some.
...
31
votes
5
answers
3k
views
Test driven development - convince me! [closed]
I know some people are massive proponents of test driven development. I have used unit tests in the past, but only to test operations that can be tested easily or which I believe will quite possibly ...