A Panic test is simply a Psychology test. If the test is passed, everything is fine, but if the test is failed the unit will immediately flee as described further down.
Note that a unit only needs to take one Panic test in each phase (Movement, Magic, Shooting and Close Combat) even if there are multiple reasons to take Panic tests. Some Panic tests are taken immediately, and in larger games you will find it helpful to mark units that have already taken Panic tests, in order that you do not end up mistakenly taking another as the phase goes on.
If two or more units from the same army have to take Panic tests at the same time, the controlling player chooses the order in which tests are made.
It is worth noting however that there are three circumstances under which units are not forced to take Panic tests:
A unit does not take Panic tests if it is in close combat.
A unit does not take a Panic test if that unit is already fleeing.
A unit does not take a Panic test if it has already passed one earlier in the phase.
Assuming a unit is not subject to the circumstances described above, the most common circumstances under which it must take a Panic test are: Heavy Casualties, Nearby Friend Annihilated, Nearby Friend Breaks, Fled Through