"Stub" comes from Middle English stubbe, a tree stump; the sense of "short remaining part" gave both the ticket stub and the placeholder meaning.
The word entered English around the 12th century as stubbe, a stump or the trunk of a felled tree. By the 16th century it meant any short remaining piece. That physical sense survives in "pencil stub", "ticket stub" and "cigarette stub". In the 20th century it became a metaphor for anything incomplete: a Wikipedia stub, a database stub, a test stub. The common thread is: something shorter than the whole, kept so the whole can be recognised.
Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.
— Martin Fowler, *Mocks Aren't Stubs*, 2007