How to mock Eureka when doing Integration Tests in Spring?

妖精的绣舞 提交于 2019-12-04 03:46:56

Another solution is to disable the Eureka Client in your application.properties or application.yml file under test/resources

applications.properties:

eureka.client.enabled=false

application.yml:

eureka: client: enabled: false

This has the benefit of not needing to remeber to include the system property for every JUnit test that requires disabling the Eureka Client.

You can set a system property for eureka.client.enabled=false for tests.

If you're running the tests using gradle you can do this:

tasks.withType(Test) {
    systemProperty 'eureka.client.enabled', 'false'
}

If you're running tests in an IDE then you'll have to set the system property there as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!