实现springBoot单元测试

1.测试业务层数据库交互数据进行单元测试;
2.直接配置入口程序类进入注解中TeacherApplication,就能加载程序的application.properties文件

import org.junit.Test;
import org.junit.runner.RunWith;
import cn.com.ultrapower.core.utils.SpringContextUtils;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {TeacherApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class NatifyTest {

private PreviewLogService previewLogService;

 @Test
public void testDuration() {

    previewLogService = SpringContextUtils.getBean(PreviewLogService.class);
    PreviewLog previewLog = new PreviewLog();
    previewLog.setMainId(Long.valueOf(26));
    previewLog.setKnowledgeId(Long.valueOf(217));
    previewLog.setContentId(Long.valueOf(106));
    previewLog.setUserId(Long.valueOf(119));
    previewLog.setState("1");
    int duration = previewLogService.duration(previewLog);
    System.out.println(duration);
}
}

(http://blog.csdn.net/qq_27093465/article/details/52919744)

猜你喜欢

转载自blog.csdn.net/weixin_43450799/article/details/89886682