加入
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>1.5.1.RELEASE</version> </dependency>
@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = FirstBootDemoApplication.class) public class TestUser { @Autowired private UserDao userDao; @Test public void testAddUser(){ User user = new User(); user.setName("jkf"); user.setAge(25); user.setId(1); userDao.addUser(user); } @Test public void testFindByName(){ User user = userDao.findByName("jkf"); System.out.print(user.getAge()); } }