Well in this case it was factory testing and had nothing to do with software.
In the case of VW, I highly doubt those software engineers were told plainly what they were doing. While I agree they have an obligation also keep in mind speaking up would probably be career suicide.
The liability is on the executives that make take these illegal actions.