Abstracting the operating system for unit test



How do others unit test embedded software? It seems only natural to me
to do it on a PC, rather than on target. But that means calling stubs
instead of operating system functions like send/receive message, spawn/
kill task, start/expire timer, etc

Do you just use #defines? Or how do you handle this?

.