@JLeslie
A routine was intentionally added to one of the car’s computers that told the car when it was in an emissions test condition.
This caused the cars to set engine parameters that reduced emissions to a legal level when being tested. Once the car was back on the road engine settings returned to the normal range (all modern engines are “driven” by a computers that change engine settings constantly for optimum efficiency in a given driving situation) Engines even take things into account such as air density, humidity, temperature and much more.
Note that when I say efficiency I mean aspects like power, fuel economy, etc., not necessarily low exhaust emissions.
This illegal but clever “feature” of the Volkswagen diesels was not discovered by any official agency. It was found by West Virginia University scientists using portable test equipment that worked when the car was driven in real world conditions.