1

I only want to run a test if a specific property is set in the application.yml (it's really injected via environment variable into the yml). How would I do this?

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

tests:
  ignore: ${SOME_ENV_VAR}

Test Class:

@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...
    }
}
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
  • Does this question help you: https://stackoverflow.com/questions/1689242/conditionally-ignoring-tests-in-junit-4 ? – tkruse Dec 07 '17 at 00:24
  • @tkruse Unfortunately, no. I need the class to not even start loading the configs or base classes. – Don Rhummy Dec 07 '17 at 00:32
  • Did you try putting Assume.assumeTrue... into @BeforeClass annotated method? This might require manually loading the YAML / reading the env variable – tkruse Dec 07 '17 at 01:01
  • @tkruse I didn't try that, but I will look into that. Not sure about manually loading the yaml, that seems likely to lead to error. – Don Rhummy Dec 07 '17 at 01:08

0 Answers0