I think you might have an overly broad conception of the duties of a teacher towards students. They should protect them from harm, so laying an actual trap (or just not warning about a potential danger) so that a student gets hurt would be in violation of the teacher's duty. But giving your students a test to make sure they're actually studying is such a common (and common-sense) expression of distrust that I'd be surprised if it were illegal to not expect good faith from their students.
Relevant: §2 LehrErzVDBest https://www.gesetze-im-internet.de/lehrerzvdbest_1/DDNR00019... (Former GDR law that was kept in force after reunification. Not sure whether the part about not doing damage to the socialist society is still part of current law.)
From what I read from the reference in your comment, that law applies to the part which forms the former gdr in germany.
According to that website (run by two official ministries) the law is current and your comment about that part surprises me as well.
Whoops, sorry. I used to wonder why people make the elementary mistake of not noticing they're talking to a different person. Now I know: it's because the "threads" view shows the replies to your own comments, but not the comment you originally replied to. So there's not enough context to notice that the usernames are different.
I'm not your lawyer, so this is just my 2 cents. If you're specifically asking for legal help, please consult a lawyer on your behalf so you can discuss the details.