The present invention provides a hydroxyacyl-coenzyme A dehydrogenase gene, an acyl-coenzyme A thiolase gene, genetically engineered strains and a use thereof. The hydroxyacyl-coenzyme A dehydrogenase gene encodes a protein (i) or (ii) as follows: (i) having an amino acid sequence according to SEQ ID NO 2; (ii) derived by substituting, deleting or inserting one or more amino acids in the amino acid sequence defined by (i) and having the same function as that of the protein of (i). The present invention constructs genetically engineered Mycobacterium strains lacking of a hydroxyacyl-coenzyme A dehydrogenase gene or an acyl-coenzyme A thiolase gene, which are used in the preparation of steroidal compounds, such as 1,4-BNA, 4-BNA, 9-OH-BNA, etc. Further, the invention improves the production efficiency and product quality of steroidal drug, improves the utilization of drug precursors, reduces the production costs, and provides the advantages of mild reaction conditions, environmentally friendly, and high economic and social benefits.