junit4加入
@RunWith(SpringRunner.class) //主要
@SpringBootTest(classes = MyApplication.class) //MyApplication是springboot启动类
@Test注解使用org.junit.Test的就行。
package com.company.demo;
import com.company.demo.corporatemember.service.impl.EnterpriseServiceImpl;
import lombok.extern.slf4j.Slf4j;
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.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApplication.class)
@Slf4j
public class MyTest{
@Autowired
private EnterpriseServiceImpl enterpriseServiceImpl; //mybatisplus生成的service
// @Autowired
// private EnterpriseMapper enterpriseMapper; //mybatisplus生成的mapper
@Test
public void getMemberInfo() {
String data = "data";
enterpriseServiceImpl.getMemberInfoToUpdate(data);
}
}
如果是找不到方法,看看test目录下,是不是有同名类,测试类引入了不正确的类造成的。
junit5,应该是这样
@ExtendWith(SpringExtension.class)
@SpringBootTest
相关
springboot 2.0 springboottest 事物自动回滚,事物不自动回滚 @Transactional @Rollback_@rollback的