<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
@RunWith(SpringRunner.class) //底层用junit SpringJUnit4ClassRunner
@SpringBootTest(classes = Boot1testApplication.class) //启动整个springboot工程
@Test
public void fangfa1()
{
// stringRedisTemplate.opsForValue().set("key1","value1");
String key1 = stringRedisTemplate.opsForValue().get("key1");
System.out.println(key1);
}
常见错误
JUnit测试提示Java.lang.Exception: No runnable methods
原因:没有在方法上指定@Test和@Test的包导错了
@Test导入的包错了,spring-test需要的Junit是org.junit.Test