1. A surface inspection apparatus, comprising: an illuminating optical system that irradiates illuminating light onto a surface of a test piece, with the surface formed by stacking a plurality of pattern layers; an image-capturing device that captures an object image based upon diffracted light from the test piece; a condition control device that sets or changes an apparatus condition at which the object image is to be captured by said image-capturing device; and a condition detection device that takes in the object image captured by said image-capturing device every time the apparatus condition is changed by said condition control device and determines an optimal condition for the apparatus condition for inspecting the pattern layers based upon the object image thus taken in, wherein: said condition detection device determines an optimal condition for the apparatus condition by using an image taken in before forming an uppermost pattern layer, also determines the optimal condition for the apparatus condition by using an image taken in after forming the uppermost pattern layer and judges as to whether or not an image captured by said image-capturing device corresponds to the uppermost pattern based upon the plurality of optimal settings thus determined.