Update: added the difference from integration tests at the end of the post.
Here’s my latest definition of what a unit test is:
A unit test is a fast, in-memory, consistent, automated and repeatable test of a functional unit-of-work in the system.
A unit of work is any functional scenario in the system that contains logic. it can be as short as a function, or it can span multiple classes and functions, and it provides internal or business value to the system under test.
how is it different that an integration test?
An integration test usually is not in-memory: it may touch the disk file system, databases, registry or other shared resources. It may read or need a configuration file of the file system, wheas a unit test can be fully configured in-memory, for example.
An integration test will usually run much slower because it does not run in-memory.
An integration test can be less consistent – it may use threads or random number generators so that the result of the test is not always consistent.