I highly value humor and love to entertain whenever I can. In formal writing, I would encourage you to go ahead and write something that you think would be funny. Then reread it. Then reread it again. Read it aloud. Read it silently. Read it again tomorrow while you edit it. And read it again. And again. And again. Imagine reading it out loud to the people with the least sense of humor you know. Imagine reading it to a person with a furrowed brow, in a bad mood, who is trying to find anything they can to rip apart what you have laid down, to find a reason to cast it aside as useless junk.
Then read it 10 more times, as any good writer must inevitably do. Now imagine reading it again in 10 years (if you are lucky and what you've done turns out to be of use).
Personally, I have found that after the 20+ time I've read something, it isn't even funny to me anymore - and I think I'm hilarious! But even the best jokes I've ever told never landed 100% of time, or to 100% of the audience - and in formal writing I don't even know who the audience is - they might speak my language as a 2nd (or 3rd or 4th) language.
Being stubborn, I like to write humor into anything I make. But after the 20th read through I realize it just isn't funny any more, even to me - and if that's how a reader would feel who doesn't get or appreciate the joke, it just isn't worth it any more to me to include it. I'm basically writing a technical instruction manual, and there's a reason those things aren't really funny - you are supposed to read them and refer back to them repeatedly, and jokes get old fast.
If I really like a joke, I'll save it for when I can make it in person, in a talk or in a presentation, when I can personally hear the laughs (or gauge the room and know to skip it entirely). Or I'll be funny on a website like this so I can wallow in a mass of glorious unicorn points.
But in formal writing like a thesis or important research paper? Well, you decide after you've read it for the 30th time if it is still worth inclusion, or if that emoticon makes you smile - or if you want to poke it in its tiny little semi-colon eye.