package mip.bigdata.cms.service.impl;
import mip.bigdata.cms.Application;
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.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
@ActiveProfiles("prod")//dev、test等
@RunWith(SpringRunner.class)
@SpringBootTest
//开始的时候环境 变量无法加载 spring.profiles.active=prod;spring.main.allow-bean-definition-overriding=true;jasypt.encryptor.password=smartone-bigdata
//@TestPropertySource("classpath:bootstrap-prod.yaml")
public class MipPostWorksTemplateServiceImplTest {
@Autowired
private MipPostWorksTemplateServiceImpl mipPostWorksTemplateService;
@Test
public void findTemplateIdsByTags() {
List<Long> tags = new ArrayList<>();
List<Long> templateIdsByTags = mipPostWorksTemplateService.findTemplateIdsByTags(tags);
System.out.println(templateIdsByTags);
}
}
加载的时候因为环境变量的加载原因:导致 测试类一直不加载 配置文件,或者配置文件报错
这里如果是多个变量 需要在 环境变量中 一个一个的设置,不能整串粘贴进来
比如:--spring.profiles.active=prod --spring.main.allow-bean-definition-overriding=true --jasypt.encryptor.password=smartone-bigdata
粘贴进来是这样的:
将多个变量合成了一个变量 ,启动命令中是可以这样的,但是环境变量中是不可以的
@SpringBootTest(classes = Application.class) 这里默认就是加载启动类,不写也可以,这样
@SpringBootTest