Among the answers given thus far, the one which is closest to my thinking is that of xLeitix, and the side note about the context applies too.
Is it professional for a professor to ask “surprise” questions on a test?
It can be professional. As I said in a comment, it's unprofessional to ask such questions with the only purpose of failing as many students as possible.
Moreover, I don't like very much the adjective surprise in the title: a surprise is something unexpected, but if a professor clearly warns the students that at the exam they will find problems which have not been solved during the course, there is no surprise. So, in the following, I will talk about "new" problems.
Exams and tests have, as their main goal, that of assessing how well students master/understand a (small portion of a) certain subject. As others have well explained, new questions or problems can give a hint on how deep this understanding is.
But apart from the above stated main goal, exams and tests might also have secondary goals:
- An exam can be an occasion for learning new stuff. The well defined separation between learning and verification, which typically happens in a course, is something that drastically comes to an end when one starts working, even in academia. Learning and verification in everyday life are really interleaved, and many times learning has to be done along a stressful verification. So, a new problem during an exam can be an occasion to continue learning in a more "unprotected" way.
- An exam can be a hint, one of the many, that what has been taught during the lessons is not the whole story, and that beyond the lessons there is much more: new problems surely deliver this message.
- For a professor, an exam is an occasion to fish for good students to whom propose a thesis. Giving new problems can be a way to find students who are capable of independent thinking.
So, I tend to give new problems at the exams keeping in mind the above points.
To avoid being too general, let's make an example related to my experience. A few years ago I taught a course about sensors, transducers and signal conditioning circuits for graduate electronic engineers. The written part of the exam consisted in one problems about designing or analyzing a signal conditioning circuit or about evaluating the measurement uncertainty of certain transducer. Due to the vastness of the topic, the course could neither describe all kind of sensors and transducers, nor all possible signal conditioning circuits. So, I decided that every exam would have been made of a new problem, where "new" meant:
- A problem about a transducer not described in the course. Indeed the exam text contained a short description of this kind of transducer.
- A problem about the analysis and/or design of signal conditioning circuit not described in the course. The students, being electronic engineers, were expected to know how to analyze electronic circuits, even of moderate complexity. In more difficult cases, hints were provided.
- A problem about a known transducer applied in an unknown way.
Exams were open books and students could bring the solutions of all previous exams and all the class notes. After the written part, if successful, there was an oral examination which was more about class material.
What was the outcome of this kind of exam? The course was in general very well received by the students, even if the exam was considered hard: the percentage of success was around 30% (the pass grade is 60%). The major complaint was about the number of exercises solved during the classes, but this happens in all kind of courses. My answer to this complaint was that there were, indeed, time constraints that prevented us to solve more problems but, anyway, whatever the number of problems solved during the course, at the exam they would have found a new one (sometimes students ask for more solved problems in the hope that these will exhaust all possible cases).
From this and other experiences along 15 years, I think that students can withstand new problems at the exams as long as the motivations are well explained and, especially, as long as the course is worth of it.