常见问题:
1.junit注解无法使用
junit依赖中添加了<scope>test</scope>junit中的注解需要在项目中src下的test文件夹(如删了或没有需要自己建)新建一个目录设为
Test Resources Root,此文件夹下的java测试类才能使用junit注解
2.测试类的问题
(1)@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring/applicationContext-redis.xml"})此为ssm项目下可运行的在类上注解,其中
SpringJUnit4ClassRunner若为其他可能无法使用@Autowired进行测试,反正JUnit4不行,其他有待确认。
(2)@ContextConfiguration为需要加载的配置文件,应该为精确的路径,要不然会报错
3.springboot测试类问题
1.保证springboot测试类正常运行还要加上两个注解
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
2.Springboot 项目的启动类 和 单元测试类的包名必须相同