Everyone likes to laugh, right? We all like to smile, be happy, be humored. In the midst of a serious and trying time, a good laugh can go a long way. The same applies in books.
Code Name Verity by Elizabeth Wein was about a very serious, tough, and depressing topic: Nazi prison camps. However, Verity's sarcastic wit provided a nice respite from the hard topic. It wasn't too far to where it seemed almost mocking of the topic, but it provided a brief moment of "Wow. She's a strong character, being able to make such witty comments in such a dire situation." In fact, aside from the hype, I think Verity's voice was what pulled me though the beginning of the book (that was, admittedly, a little slow for me).
Under the Never Sky by Veronica Rossi doesn't explore as tough of a subject as Code Name Verity does, but, like most novels, the characters go through some hard times. However, Roar's there to save the day with a bit of comedic relief! (Roar also happens to be one of my favorite literary characters of all time, just so you know. XD) Roar's such a fun-loving, happy go lucky, funny guy that while, yes, he can definitely be serious and he doesn't try cracking jokes at a bad time, he's that guy that'll be able to make you laugh on your gloomiest day.
Divergent by Veronica Roth has a guy name Uriah. He reminds me a bit of Roar, in that he's a charismatic, very confident, funny character. (He's also my favorite character in this trilogy). He, too, can be serious, but he can also make the characters laugh at just the right time.
Fred and George Weasley from Harry Potter are probably some of the most notable comedic characters in literature. Admittedly, I haven't read the series, but I've seen the movies after my friends (who are huge fans) made me have a marathon with them. And I don't think this list would be complete without these two characters.
Notice how none of the books I just mentioned were "comedies." However, they're all improved by having a good comedic character (or two).
I'd recommend, if at all possible, having a character in your cast whose sarcasm, wit, or plain shenanigans can provide moments of light in a dark time. Now, finding a balance is necessary, of course. Too much comedy, and it can seem that the author's making light of a topic that's incredibly serious, even if that was by no means the author's intention. However, a little trace of comedy here and there can provide for a nice respite for the readers, and even for the characters.
The best advice for finding a good balance I can think of is just thinking about the person in your life that can make you laugh at just the right time to cheer you up just enough when you need it most. Use them and the memories you have of them brightening your day as a model for your characters' interactions. Memories and experience really can help add a layer of realism to our writing.
So, who are some of your favorite comedic characters? Have you written any characters like this?