Computer-generated hologram (CGH) is an effective way to compensate wavefront in null test of aspheric surfaces and freeform surfaces. Our strategies of CGH design and fabrication for optical testing are presented, and an experiment demonstrating the compensation results of CGH and null lens is also reported. In order to design complex CGH, software was developed, with which we can design a CGH including three sections: main section for compensating wavefront in null test, alignment section for adjusting the relative position between CGH and interferometer, and fiducial section for projecting fiducial marks around the optics under test. The design result is represented in GDS II format file which could drive a laser-direct-writer-machine to fabricate a photomask. Then, a 1:1 replication process is applied to duplicate the patterns from photomask to a parallel optical substrate whose surface is error better than λ/60 rms. Finally, an off-axis aspheric surface was tested with CGH and null lens respectively. The test result with CGH (0.019λrms) is almost the same as the result with null lens (0.020λ rms). This experiment also demonstrated that fiducial marks projected by CGH can be used to guide the alignment of the optics and measurement of its off-axis distance.