Now I understand the concept , that an engine needs compression to make efficient power and I understand the theory , but what I don’t completely understand is how does compression build in a compression test(a gauge test in a gasoline engine) over multiple revolutions, in theory , shouldn’t the compression be removed from the engine since multiple revolutions of the crank shaft would open the exhaust valve and allow all the air to escape the cylinder assuming the engine is in time ? Please help me understand(go in depth)
The pressure gauge has a one way valve in it so that it does not follow the pressure in the cylinder at all times - it is designed to record the maximum pressure over several cycles of the engine.
The pressure gauge used for this test also has a button on the side (back or connecting tube) to release the pressure. This also allows for the reading to be read easily - as trying to read a jumping needle is difficult...
Edit as this is useful info :
On the compression stroke the pressure increases as the piston moves up the bore which reduces the available volume for the fixed amount of air. So if you think about Boyles' and Charles' Laws for gases pV = nRT or pVγ = constant... The spark ignition engines rely on the increase of not only the pressure but the increase in temperature as it is the temperature that causes the ignition of the injected fuel.
Here is an image of a compression tester, has an extension adapter connected, the total length of the tube is good as it keeps your fingers away from rotating parts (always a good thing) and you can see the button on the left on the steel hexagon below the gauge.
The maximum pressure obtained inside the cylinder is achieved at top dead centre (when the piston is at the top of the stroke). There is a very small volume of gas in the cylinder at this point.
When you add a compression tester as in the one in Mike's answer (which probably has a larger volume than most I have seen), you are likely doubling the volume at TDC. This will probably lead to half the pressure that you would get without the tester connected on the first compression stroke.
Since the compression tester has a none return valve, when cylinder pressure is released on the next exhaust stroke, half of the volume (in the compression tester) will remain at pressure. The valve is not just to record the maximum pressure over several compression strokes. Without this valve, the correct compression pressure would never be reached due to the increase in volume at TDC.
On the next compression stroke, you have again twice the volume, but half of the volume is at half expected maximum pressure. This time the pressure increases further.
What you see is over several compression strokes, twice the normal volume is pumped to the normal compression pressure. This is why you see the pressure increasing in pulses while cranking until it eventually stabilizes at a maximum pressure.
Image taken from - https://images-na.ssl-images-amazon.com/images/I/41JS6DGRRNL.jpg