Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
A unit is the smallest testable part of an application. In procedural programming, a unit may be an individual function or procedure. Unit tests are created by programmers or occasionally by white box testers.
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 tests should fail for
exactly one reason, that’s…
It seems reasonable to me that if a serious bug is found in production by end-users, a failing unit test should be added to cover that bug, thus intentionally breaking the build until the bug is fixed. My rationale for this is that the build should…
I find tests a lot trickier and harder to write than the actual code they are testing. It's not unusual for me to spend more time writing the test than the code it is testing.
Is that normal or am I doing something wrong?
The questions “Is unit…
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. In the past, each time we tried it, everyone got…
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 noticeable flaws:
Shuffle the array, then make sure its…
I have been tasked with writing unit tests for an existing application. After finishing my first file, I have 717 lines of test code for 419 lines of original code.
Is this ratio going to become unmanageable as we increase our code coverage?
My…
I work in a small company as a solo developer. I'm the only developer at the company in fact. I have several (relatively) large projects I've written and maintain regularly, and none of them have tests to support them. As I begin new projects I…
Some people maintain that integration tests are all kinds of bad and wrong - everything must be unit-tested, which means you have to mock dependencies; an option which, for various reasons, I'm not always fond of.
I find that, in some cases, a…
In my current project (a game, in C++), I decided that I would use Test Driven Development 100% during development.
In terms of code quality, this has been great. My code has never been so well designed or so bug-free. I don't cringe when viewing…
I'm a solo developer with a pretty time-constrained work environment where development time ranges usually from 1-4 weeks per project, depending on either requirements, urgency, or both. At any given time I handle around 3-4 projects, some having…
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.
The problem is, I don't know what to test. Should I…
I understand the value of automated testing and use it wherever the problem is well-specified enough that I can come up with good test cases. I've noticed, though, that some people here and on StackOverflow emphasize testing only a unit, not its…
I frequently work with very numeric / mathematical programs, where the exact result of a function is difficult to predict in advance.
In trying to apply TDD with this kind of code, I often find writing the code under test significantly easier than…
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 work on different kinds of projects from me - they work…