Stub Runner Spring Cloud
Stub Runner 可以与 Spring Cloud 集成。
Stub Runner can integrate with Spring Cloud.
有关实际示例,请参阅:
For real life examples, see:
Stubbing Service Discovery
Stub Runner Spring Cloud
最重要的特性在于它可以模拟:
The most important feature of Stub Runner Spring Cloud
is the fact that it stubs:
-
DiscoveryClient
-
ReactorServiceInstanceLoadBalancer
这意味着,无论您使用的是 Zookeeper、Consul、Eureka 还是其他任何服务,在您的测试中都不需要它们。我们正在启动 WireMock 实例作为您的依赖项,并且当您使用 Feign
时,我们会告诉您的应用程序加载一个平衡的 RestTemplate
或 DiscoveryClient
以直接调用这些模拟服务器,而不是调用真正的服务发现工具。
That means that, regardless of whether you use Zookeeper, Consul, Eureka, or anything
else, you do not need that in your tests. We are starting WireMock instances of your
dependencies and we are telling your application, whenever you use Feign
, to load a
balanced RestTemplate
or DiscoveryClient
directly, to call those stubbed servers
instead of calling the real Service Discovery tool.
Test Profiles and Service Discovery
在您的集成测试中,您通常不想调用发现服务(例如 Eureka)或配置服务器。这就是您创建附加测试配置来禁用这些功能的原因。
In your integration tests, you typically do not want to call either a discovery service (such as Eureka) or Config Server. That is why you create an additional test configuration in which you want to disable these features.
由于 spring-cloud-commons
具有某些限制,为实现此目标,您必须禁用静态块中的这些属性,如下例(针对 Eureka):
Due to certain limitations of spring-cloud-commons
,
to achieve this, you have to disable these properties
in a static block such as the following example (for Eureka):
//Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156
static {
System.setProperty("eureka.client.enabled", "false");
System.setProperty("spring.cloud.config.failFast", "false");
}
Additional Configuration
您可以使用 stubrunner.idsToServiceIds:
映射将存根的 artifactId
与应用程序的名称进行匹配。
You can match the artifactId
of the stub with the name of your application by using the stubrunner.idsToServiceIds:
map.
默认情况下,所有服务发现都是被截断的。这意味着无论你是否有一个现有的`DiscoveryClient`,它的结果都被忽略了。但是,如果你想重新使用它,你可以将`stubrunner.cloud.delegate.enabled`设置为`true`,然后你现有的`DiscoveryClient`结果将与被截断的结果合并。 |
By default, all service discovery is stubbed. This means that, regardless of whether you have
an existing |
Stub Runner 使用的默认 Maven 配置可以通过设置以下系统属性或相应的环境变量来微调:
The default Maven configuration used by Stub Runner can be tweaked either by setting the following system properties or by setting the corresponding environment variables:
-
maven.repo.local
: Path to the custom maven local repository location -
org.apache.maven.user-settings
: Path to custom maven user settings location -
org.apache.maven.global-settings
: Path to maven global settings location