Definition
The definition you referred to is Oxford Learners Dictionaries: congratulation: "1 congratulations [plural] a message congratulating somebody (= saying that you are happy about their good luck or success)."
"Congratulations" comes after the success is achieved, and you are saying that you observed their success or good luck and approve of it.
"Good luck" must come before their success - you are saying you hope they will succeed.
Congratulations and good luck!
You could congratulate someone for taking a prestigious exam, such as a bar exam, especially if the person was expressing a positive sentiment at the fact that they had finally reached this point:
Jane: "Hey Joe, guess what!"
Joe: "What!"
Jane: "I'm almost finished! Tomorrow I'm sitting for the bar exam!"
Joe: "Congratulations!"
(You might also say "Congratulations! And good luck!")
"Taking an exam" vs. "doing an exam"
While "I'm taking an exam" is much more common, there are other phrases that are acceptable or even preferred within certain dialects of English. Note the following Google N-Gram:
Google N-Gram: do an exam,doing an exam,take an exam,taking an exam,sit an exam,sitting an exam,sit for an exam,sitting for an exam,have an exam,having an exam,got an exam
Some of these results have a different context, such as a doctor who says, "I'm doing an exam" is performing an exam on someone. However, there are instances of "doing an exam" referring to the same meaning as "taking an exam" within the exact same idiomatic scenario. (There are also some subtle cases in different scenarios that could influence usage.) It would be conservative to use the phrase "I'm taking an exam" unless the culture you're in uses a different idiomatic phrase.
Credit to @Adam and other commenters for ideas and content of this answer.