controller的对象不能用 new ,应该用 @autowired 自动注入
另外:使用测试类时应该注意的地方
1:需要导入junit依赖
<!-- Junit依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
2:在测试类的上方应该使用这两个注解
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@RunWith注解中的属性,junit4.4前后是不同的:4.4之前为BlockJunit4ClassRunner,之后为Junit4ClassRunner