As you did not mention in which language environment you code...
As I work in Smalltalk, syntax is checked in the editor while I type, and whenever I accept a method, so thats not an issue. (For those who don't know Smalltalk: it is not file-based, but object oriented; that means that you add method-objects one-at-a-time to a class object, and the system compiles each as it is "accepted" in the editor).
For small methods which are algorithmic or which do not need a big framework/setup, I add a little comment which tests that method and which can be executed by a click. There is also a test-runner to extract all these and run them as a unit test.
For bigger stuff, a TestCase class is updated for every few methods and the test-runner button clicked from time to time, stopping me on a red light.
So I would say, a test is done for every 10 lines or so.
I admit, doing so requiresd a highly reactive and incremental IDE - otherwise, it cannot be done so easily and I would revert to say a roughly a letter-size page-of-code before testing. I do not consider compilability as "a test", so syntactic correctness does not count.
EDIT: For your amusement, here is a concrete example from the Collection class:
For those who don't know smalltalk:
quoted strings are comments;
+/- is an operator to create a measurement value;
/ creates fractions;
{...} is array creation;
the testcases at the end are directly executable (so called doIt) from within the editor.
sum
"sum up all elements.
This is implemented using a variant of the normal inject:into: pattern.
The reason for this is that it is not known whether we are dealing with number
(i.e. if 0 is a good initial value for the sum).
Consider a collection of measurement or physical objects, 0 would be the unitless
value and would not be appropriate to add with the unit-ed objects."
| sum sample |
sample := self anElement.
sum := self inject: sample into: [:accum :each | accum + each].
^ sum - sample.
"
TestCase should: [ { } sum ] raise:Error.
TestCase should: [ '' sum ] raise:Error.
TestCase assert: ( { 1 } sum = 1 ).
TestCase assert: ( { 1. 2. 3. 4. } sum = 10 ).
TestCase assert: ( (1 to:10) sum = 55 ).
TestCase assert: ( 'abc' asByteArray sum = 294 ).
TestCase assert: ( { 10 +/- 2.
20 +/- 4.
100 +/- 10 } sum = (130 +/- 16) ).
TestCase assert: ( { (1 / 9).
(1 / 7).
} sum = (16 / 63) ).
"