我有一个在 AWS 云上运行的协议代理。我可以在 demo.service.aws.cloud/demo-service/latest 之类的示例 url 上看到一些描述说“app-a-service 和 app-b-service 之间的协议”显示了交互。这是对经纪人:
A pact between express-demo-service and spring-demo-service
Requests from express-demo-service to spring-demo-service
Get test envs given tEST_ENV and SECRET_ENV set
Interactions
Given tEST_ENV and SECRET_ENV set, upon receiving get test envs from express-demo-service, with
{
"method": "GET",
"path": "/env",
"headers": {
"Authorization": "Bearer "
}
}
spring-demo-service will respond with:
{
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"TEST_ENV": "foo",
"SECRET_ENV": "bar"
}
}
现在我构建了我的 Springboot 休息控制器,它返回文档中定义的那些响应。我现在如何运行测试以确保我的实现满足协议代理的这些要求?
以下是我的 TestPacts,以确保我的实现符合经纪人的合同(不确定这是否正确):
@RunWith(PactRunner.class)
@Provider("test_provider" )
@PactBroker(host = "https://mybroker.aws.com/pacts/provider/spring-demo-service/consumer/express-demo-service/latest", port = "80")
@VerificationReports({"console", "markdown"})
public class TestPacts {
private static final Logger LOG = LoggerFactory.getLogger(TestPacts.class);
private static ConfigurableApplicationContext application;
@TestTarget
public final Target target = new HttpTarget(8080);
@BeforeClass
public static void startSpring(){
LOG.info("starting application");
application = SpringApplication.run(ProviderServiceApplication.class);
}
@State("default")
public void toDefaultState() {
LOG.info("Now service in default state");
}
@State("extra")
public void toExtraState() {
LOG.info("Now service in extra state");
}
@AfterClass
public static void kill(){
LOG.info("stop application");
application.stop();
}
}
当我运行时,我得到错误:
org.junit.runners.model.InitializationError
at au.com.dius.pact.provider.junit.PactRunner.initialize(PactRunner.kt:93)
at au.com.dius.pact.provider.junit.PactRunner.getChildren(PactRunner.kt:140)
at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:426)
at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:351)
at com.intellij.junit4.JUnit4IdeaTestRunner.getDescription(JUnit4IdeaTestRunner.java:78)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)