1.添加相关repo:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
2.添加注解@:
测试对象:@SpringBootTest(classes=obj.class)
测试工具:@RunWith(SpringJUnit4ClassRunner.class)
整合web:@WebAppConfiguration
class
自动注入:@Autowired
private obj
测试方法:@Test
public void method{TestCase.assertEquals}
问题:JUnit中配置文件属性无法加载@ConfigurationProperties("prefix")?
使用@EnableAutoConfiguration,自动配置Spring上下文,完成bean的配置。
也可以使用@SpringBootApplication(扫描包)。