It depends on what level (and type) of schooling, the system, and the school itself.
I've been in classes with teachers that taught just enough to pass the tests, and fantastic teachers that covered a lot of extra interesting content, from primary school, through secondary, and even in university. I've also been on the teacher-assessment end, where even though my co-teacher and I scrambled to fill in huge knowledge gaps caused by insufficient prerequisites being stated for the subject, the higher than normal fail rate was rigorously questioned.
In places where teachers are 'graded' on how well their students perform, I think many would teach to best prepare for tests. This is one of the drawbacks of teacher-assessment - where salary, bonuses, responsibility, teaching schedules, further training, and career advancement may depend on how the students' results. It's worse when teacher-assessment is done across cities, regions, schools or even across classes.
It is not good when a subject/class is assigned to a teacher, and it is not their speciality or in their area of interest. Then teaching to meet test requirements is common. Teachers who are enthusiastic (it's contagious), and knowledgeable are often able to motivate students to learn more thoroughly, above and beyond the test prep.
Although many teachers try to teach more than what is required to pass assessment tasks. However, many students are test and score focused - the information they retain is specifically for exams. Extra information, not needed on the test, is often forgotten.