[英]Pact framework - running one test only
I wrote a provider test class using PACT, that has two tests.我使用 PACT 编写了一个提供程序测试 class,它有两个测试。 The tests successfully run when I run the entire class, but I can't run one test only by right clicking one @State, as no tests seem to be found.
当我运行整个 class 时,测试成功运行,但我不能仅通过右键单击一个 @State 来运行一个测试,因为似乎没有找到任何测试。 Any ideas as how could I run in IntelliJ one test only?
关于如何仅在 IntelliJ 中运行一项测试的任何想法? Provider test class:
提供商测试 class:
@consumer("teh_consumer")
@Provider("teh_provider")
@PactBroker
@IgnoreNoPactsToVerify
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
//@SpringBootTest
public class TehAppContractTests {
@TestTarget
public final Target target = new SpringBootHttpTarget();
@State("Teh services are up")
public void testServicesUpRequest() {
}
@State("Teh services are down")
public void testServicesDownRequest() {
}
}
Stack trace:堆栈跟踪:
java.lang.Exception: No tests found matching Method testServicesUpRequest(com.teh.contract.TehAppContractTests) from org.junit.internal.requests.ClassRequest@191e654
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
From what I know, the only way to verify specific interactions is to use @PactFilter据我所知,验证特定交互的唯一方法是使用 @PactFilter
https://docs.pact.io/implementation_guides/jvm/provider/junit#interaction-filtering https://docs.pact.io/implementation_guides/jvm/provider/junit#interaction-filtering
So to do this dynamically, we could to pass the interaction filter value as an env variable to the test runner.因此,要动态地执行此操作,我们可以将交互过滤器值作为环境变量传递给测试运行器。
In order to do this via IntelliJ, you could create a gradle task based run configuration that sets this up for you (only if you want it dynamically).为了通过 IntelliJ 执行此操作,您可以创建一个基于 gradle 任务的运行配置,为您设置它(仅当您需要动态时)。 For static ones you can hardcode the values in your @PactFilter annotation.
对于 static ,您可以硬编码 @PactFilter 注释中的值。
Also just to add to your question regarding @State… States are in general similar to a @Before block.还只是为了补充您关于@State 的问题......状态通常类似于@Before 块。 They don't execute any tests but sets up the app for you in a desired state.
他们不执行任何测试,而是在所需的 state 中为您设置应用程序。
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.