IDEA中的JUNIT测试

安装插件

Ctrl+Alt+s→Plugins→junitgenerator v2.0

 

Alt+insert 选中JUnit test 中JUnit4

package test.com.demo.controller; 

import com.baomidou.mybatisplus.plugins.Page;
import com.demo.DemoApplication;
import com.demo.entity.User;
import com.demo.error.ErrorCode;
import com.demo.exceptionHander.BusinessException;
import com.demo.service.IUserService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
/** 
* UserController Tester.
* springboot 需要添加的注解@SpringBootTest(classes = DemoApplication.class)
* springmvc 添加 @ContextConfiguration(locations="classpath:spring.xml")
* @since <pre>五月 13, 2019</pre>
* @version 1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class UserControllerTest {

    @Autowired
    private IUserService userService;

    private long times;

    @Before
public void before() throws Exception {
        times= System.currentTimeMillis();
        System.out.println("测试开始"+times);
} 

@After
public void after() throws Exception {
    System.out.println("测试结束"+(System.currentTimeMillis()-times));
} 

/** 
* 
* Method: getPage(@ApiParam(required = true,name = "current",value = "用户数据第几页")Integer current, @ApiParam(required = true,name = "size",value = "用户数据展示个数")Integer size) 
* 
*/ 
@Test
public void testGetPage() throws Exception {
   
} 

} 

 

posted @ 2019-05-13 17:57  TracyRanch  阅读(304)  评论(0编辑  收藏  举报