There is a nice and succinct article by
The tech behind how Volkswagen tricked emissions tests
Here is how they did it from the article:
"In the end, the detailed requirements for each test gave Volkswagen the
advance knowledge it needed to teach its cars when to behave more
cleanly. By measuring how long the engine was running, the vehicle’s
speeds, and even seemingly esoteric factors, such as the position of the
steering wheel and barometric pressure, Volkswagen vehicles could
understand they were being tested and so adjusted their engine
performance to pass the tests, according to the EPA."
The article is well worth reaching.