The testing protocol does involve driving, just driving inside on a dyno rather than outside in the "real world".One would think that the EPA would actually drive cars to get the mileage ratings, but they do not, it is a mathematical formula based on many factors, a big factor being emissions. 2 cars that get the exact same real life mileage will not be rated the same by the EPA if one has less emissions.
If you think a minute about this, it makes complete sense as the "real world" involves variable weather and traffic that is virtually impossible to account for while being fair and equitable to each vehicle mfg. Your "it is a mathematical formula" probably refers to the use of a correction factors to account for the fact that an indoor stationary dyno cant account for aerodynamic factors.... there are detailed and well-tested procedures involving outdoor testing to correct for this. Fuel usage is inferred from tail pipe emissions, but this is a scientifically proven and very accurate way to compute fuel usage, much more accurate than attempting to measure fuel usage directly.
There is a push right now to have dyno tests verified by some "real world" driving. This is not intended to replace the dyno tests but to act as a final check for reasonableness so as to avoid blatant cheating like VW did.
In short, your criticism is essentially unfounded - the EPA fuel mileage ratings, while perhaps not representing the "real world" in an absolute sense, do provide a very accurate comparative measure of how vehicles will perform in the majority of owner's hands. That is to say, if Car X gets 3 mpg higher on the rating than Car Y, then it is very likely Car X will get about 3 mpg better than Y in "real world" driving. The EPA tests have never purported to be an accurate measure of what fuel mileage individual drivers are going to get; they are a tool to compare cars and they do this quite well.
This assumes the mfgs are actually testing according to the protocol and are not making errors or "cheating", like Hyundai, Ford, and VW did. But this is a different discussion.