有没有办法在yml中设置特定属性时运行spring boot测试?

时间:2017-12-07 00:22:11

标签: java spring spring-boot junit spring-boot-test

如果在application.yml中设置了特定属性(它实际上是通过环境变量注入到yml中),我只想运行测试。我该怎么做?

YAML(src / test / resources / config / application.yml):

tests:
  ignore: ${SOME_ENV_VAR}

测试类:

@RunWith( SpringJUnit4ClassRunner.class )
@SpringBootTest(
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
@DirtiesContext

/*** DOES THIS CAUSE IT TO IGNORE THE YAML? ***/
@TestPropertySource(
    properties = {
        "someprop=TESTNS"
    }
)
@ActiveProfiles( "test-something" )

/*** PSEUDO CODE ***/
@IgnoreOnProperty( "tests.ignore=TestClass" )
public class TestClass
{
    @Autowired
    private Service service;

    @SpringBootApplication(
        scanBasePackageClasses = { SomeClass.class }
    )
    public static class Config
    {
    }

    @Before
    public void setup() throws Exception
    {
        //...elided...
    }

    @Test
    public void testSomething() throws Exception
    {
        //...elided...
    }
}

0 个答案:

没有答案