Testing formulas?

How do you make sure to find the right formula for your baby? How long do you have baby on one formula then switch?