Simulation-based scenario testing methods have drawn significant research interests， and how to find critical testing scenarios among the infinite number of concrete scenarios becomes a critical issue. To solve this problem， this paper proposed a critical scenario generation and automatic testing method for the decision and planning system based on optimization and search algorithms. The method was verified through a hardware-in-the-loop platform， and the efficiencies of different search algorithms were compared. The experiment results show that the number of critical scenarios generated by the Bayesian optimization algorithm and the genetic algorithm is increased by 3 times and 2.5 times， compared with the random search algorithm. Combined with automatic testing， the method can quite improve testing efficiency.