We describe here how planetary ephemerides are built in the framework of General Relativity and how they can be used to test alternative theories. We focus on the definition of the reference frame (space and time) in which the planetary ephemeris is described, the equations of motion that govern the orbits of solar system bodies and electromagnetic waves. After a review on the existing planetary and lunar ephemerides, we summarize the results obtained considering full modifications of the ephemeris framework with direct comparisons with the observations of planetary systems, with a specific attention for the PPN formalism. We then discuss other formalisms such as Einstein-dilaton theories, the massless graviton and MOND. The paper finally concludes on some comments and recommendations regarding misinterpreted measurements of the advance of perihelia.