相关疑难解决方法(0)

Spring Boot/JUnit,运行多个配置文件的所有单元测试

我有一个BaseTest类,它包含几个测试.每个测试都应该针对我列出的每个配置文件执行.

我想过使用参数化值,例如:

@RunWith(Parameterized.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
// @ActiveProfiles("h2-test") // <-- how to iterate over this?
public abstract class BaseTest {

@Autowired
private TestRepository test;

// to be used with Parameterized/Spring
private TestContextManager testContextManager;

public BaseTest(String profile) {
   System.setProperty("spring.profiles.active", profile);
   // TODO what now?
}

@Parameterized.Parameters
public static Collection<Object[]> data() {
  Collection<Object[]> params = new ArrayList<>();
  params.add(new Object[] {"h2-test" });
  params.add(new Object[] {"mysql-test" });
  return params;
}

@Before 
public void setUp() throws Exception {
  this.testContextManager = new TestContextManager(getClass());
  this.testContextManager.prepareTestInstance(this);
  // maybe …
Run Code Online (Sandbox Code Playgroud)

java junit spring parameterized spring-boot

8
推荐指数
3
解决办法
3875
查看次数

标签 统计

java ×1

junit ×1

parameterized ×1

spring ×1

spring-boot ×1