This is true now - it definitely wasn't in the past, especially until the 80s. My mother was still beaten (!) as a child by her teacher in Munich when she spoke too Bavarian. Eradication of dialect was the goal at the time, Hochdeutsch the only thing acceptable.
(But the reason was people thinking it's a "Bildungshindernis", a roadblock in the pursuit of knowledge, like if people speaking dialect were mentally challenged - not national unity)
Sometimes one is really just a shibboleth for the other. I grew up in Russia, and my native Southern Russian dialect was similarly derided as "uneducated peasant speech" by some schoolteachers, with a similar subtext - that, ironically, in an area where that dialect is predominant. But then you see the same argument applied to Ukrainian and Belarusian (that share some of the distinctive features) and realize that it's not just about being a "roadblock in pursuit of knowledge", even if that is used as a convenient justification that people might even genuinely believe in themselves when they use it - because they, in turn, were culturally conditioned to accept it as valid. It doesn't really make much sense as a reason when you think about it objectively, though.
(But the reason was people thinking it's a "Bildungshindernis", a roadblock in the pursuit of knowledge, like if people speaking dialect were mentally challenged - not national unity)