1.创建要测试的内容
public interface BookService {
void save();
}
@Service
public class BookServiceImpl implements BookService {
@Override
public void save() {
System.out.println("save!!");
}
}
2.测试类
@SpringBootTest
class SpringbootDemo2ApplicationTests {
//自动装配
@Autowired
private BookService bookService;
//方法名可以换
@Test
void contextLoads() {
bookService.save();
}
}
注意:主程序类和其他业务逻辑类需要在一个包下,如果不在的话SpringBoot扫描不到



