kidwon
kidwon

Reputation: 4524

@TestPropertySource annotation alternative on a method level

@TestPropertySource(locations="classpath:test.properties")
public class Aclass {}

Is there an alternative that uses properties for the tested instance in a method.

@Test
public void aMethod(){}

Upvotes: 30

Views: 14739

Answers (1)

Stav Shamir
Stav Shamir

Reputation: 998

It is still not possible, but there is an open issue for this feature if you wish to follow it.


In this issue @sergey-morenets coins a workaround if you use Junit 5. So you can just extract all the methods into inner class:

@SpringJUnitConfig(AppConfig.class)
public class ServerTest {
  @Test
  public void aMethod(){}

  @Nested
  @TestPropertySource(properties = "db.port=7000")
  public class ServerLoadConfiguration {
    @Test
    public void aMethodWithDifferentConfig(){}
  }
}

Upvotes: 19

Related Questions