要想alt+enter快捷键创建带目录结构的测试类,需要先建好测试目录,并指定为测试文件夹。
一般这样:
导入一个包即可
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
package com.kaytune.mapper;//需要有这行,否则java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
import lombok.extern.slf4j.Slf4j;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* @author hqw OK
* @date 2021-12-07 11:13
* @project cmtMyActivities
**/
@RunWith(SpringRunner.class)//作用在于,可以注入bean,否则空指针
@SpringBootTest
@Slf4j
public class Test {
@Resource(name = "ccMapper")
//@Autowired
CampaigncouponMapper campaigncouponMapper;
@org.junit.Test
public void a(){
campaigncouponMapper.delCampaigncoupon(1l);
}
}
@Resource(name = "ccMapper")
注入ccMapper