On heating an alkali earth metal or its salt, the electrons are excited easily to higher energy levels because of absorption of energy. When these electrons return to their ground states, they emit extra energy in form of radiations which fall in the visible region thereby imparting a characteristic colour to the flame.
Ba and Mg do not impart any colour to the fame i.e. they do not give flame test. This is due to their very small size. Ca, Sr and Ba impart brick red, Blood red and Apple green colours respectively to the flame