It's been known since at least 2014 that real-world emissions from many diesel cars were much higher than lab-measured emissions. There was speculation about defeat devices as well. EU regulators had recently made moves towards requiring real-world testing though unsurprisingly automakers were fiercely opposed.
For instance here's an article from February 2015 that mentions: "Campaigners say that car makers also use tricks such as programming vehicles to go into a low emissions mode when their front wheels are spinning and their back wheels are stationary, as happens in such lab experiments." (http://www.theguardian.com/environment/2015/feb/03/car-maker...)
What exactly is a real-world test then? The procedure has to be nailed down to be accurate, and at that point we're back to optimising for a given test procedure again.
For instance here's an article from February 2015 that mentions: "Campaigners say that car makers also use tricks such as programming vehicles to go into a low emissions mode when their front wheels are spinning and their back wheels are stationary, as happens in such lab experiments." (http://www.theguardian.com/environment/2015/feb/03/car-maker...)