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'll find it helpful to mark units that have already taken Panic tests, in order that you don't 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's worth noting however that there are three circumstances under which even the most cowardly of units are not forced to take Panic tests.
A unit does not take Panic tests if it is in close combat – the immediate fray blots out all other events going on around them.
A unit does not take a Panic test if that unit is already fleeing – fear has already lent wings to these warriors, the prospect of further jeopardy does not accelerate their flight.
Finally, remember that a unit does not take a Panic test if it has already passed one earlier in the phase –its nerve has been tested already!
Assuming a unit is not subject to the circumstances described above, the most common circumstances under which it must take a Panic test are: