@SpringBootTest
@TestPropertySource(locations = "classpath:application.yml")
@RunWith(SpringRunner.class)
public class ServiceTest {
@Autowired
private ChatLogService chatLogService;
@Test
public void getTaskIDTest() throws IOException {
//test something
}
}
application.yml文件
可以连接数据库,redis,mybatis等配置
server:
port: 8088
spring:
datasource:
name: test
url: jdbc:mysql://localhost:3306/test
username: root
password: xxx
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20