【发布时间】:2018-12-10 03:16:39
【问题描述】:
我想在 junit 静态类规则中访问资源/属性文件元素(在下面的代码中是 cardEventTopic 和 cardEventErrorTopic 常量)。有什么办法可以做到这一点?由于元素已经存在于属性文件中,我不想将它们作为静态常量放在测试文件中。 @Value("${}") 也不适用于静态上下文。如果有办法使这项工作有任何帮助。
@RunWith(SpringRunner.class)
@SpringBootTest(classes = PaymentAccountUpdaterApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE)
@TestPropertySource(locations = "classpath:application-messaging.properties")
public class CardIntegrationTest {
private final static String cardEventTopic = "TP.PRF.CARDEVENTS";
private final static String cardEventErrorTopic = "TP.PAYMENTS.CARDEVENTS.ERRORS";
@ClassRule
public static KafkaEmbedded kafkaEmbedded =
new KafkaEmbedded(1, false, cardEventTopic, cardEventErrorTopic);
// rest of the code
}
【问题讨论】:
标签: spring-boot spring-boot-test