springboot使用junit测试

阅读更多
springboot使用junit测试

(1)maven依赖

org.springframework.boot
spring-boot-starter-test
1.5.8.RELEASE



    junit
    junit
    4.12


(2)编写测试类
@RunWith(SpringRunner.class)
@SpringBootTest(classes=Boot.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class UserServiceTest {

@Autowired
private IUserService userService;

@Test
public void findUsers() {
List users = userService.findUsers();
Assert.assertNotNull(users);
Assert.assertTrue(users.size()>0);
}
}

(3)@SpringBootApplication启动类
@SpringBootApplication
@EnableTransactionManagement
public class Boot {
public static void main(String[] args) {
        SpringApplication.run(Boot.class, args);
    }
}



你可能感兴趣的:(springboot)