In view of the breakage of the rotary shaft of the traction motor of the locomotive, in order to ensure the reliability and safety of the equipment, this paper studies the magnetic field containing rich information in the space around the rotary shaft, so that the crack defect can be detected and the crack size can be judged in time. In order to study the influence of defect geometric parameters (width, depth and hidden depth) on the spatial magnetic field distribution around the defect in the process of eddy current testing of metal shafts, based on the principle of eddy current testing, a metal rotary shaft detection model with different defect parameters was established by COMSOL software for simulation. The horizontal magnetic induction intensity, vertical magnetic induction intensity and their respective phases are used to analyze the magnetic field distribution around the defect under different parameters. The results show that the magnetic field related parameters can qualitatively and quantitatively evaluate the crack width, qualitatively evaluate the relative size of the crack depth, and qualitatively judge whether there are hidden cracks.