在沒有存根時失敗
預設情況下,如果沒有找到存根,Stub Runner 將會失敗。要改變此行為,可以在註解中將 failOnNoStubs
屬性設定為 false
,或在 JUnit Rule 或 Extension 上呼叫 withFailOnNoStubs(false)
方法。以下示例展示瞭如何實現這一點。
註解
@AutoConfigureStubRunner(
stubsMode = StubRunnerProperties.StubsMode.REMOTE,
repositoryRoot = "stubs://file://location/to/the/contracts",
ids = "com.example:some-producer",
failOnNoStubs = false)
JUnit 4 Rule
@Rule
public StubRunnerRule rule = new StubRunnerRule()
.downloadStub("com.example:some-producer")
.repoRoot("stubs://file://location/to/the/contracts")
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
.withFailOnNoStubs(false);
JUnit 5 Extension
@RegisterExtension
public StubRunnerExtension stubRunnerExtension = new StubRunnerExtension()
.downloadStub("com.example:some-producer")
.repoRoot("stubs://file://location/to/the/contracts")
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
.withFailOnNoStubs(false);