简体   繁体   English

Pact 框架 - 仅运行一项测试

[英]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.

相关问题 如何从 json 合约进行 pact 合约验证测试 - How to do a pact contract verification test from a json contract 在常规应用程序上下文而不是测试上下文中从 API 运行测试 - Running a test from an API in regular application context instead of test context SpringBoot2:测试运行期间AspectJ的问题 - SpringBoot2: the problem with AspectJ during the test running spring 在运行测试类时启动不选择测试属性 - spring boot not picking test properties when running test classes 仅使用一个 Bean 的 Spring 上下文测试 - Spring Context Test With Just One Bean 运行 Spring Boot MockMvc 测试时“找不到返回值的转换器” - "No converter found for return value" when running Spring Boot MockMvc test 在运行 Spring 引导测试时访问配置 Class 中的 @LocalServerPort - Accessing @LocalServerPort in Configuration Class while running Spring Boot Test Junit WebClient Builder 测试用例 spring 响应式框架 - Junit test case for WebClient Builder for spring framework for reactive @MockBean 和 @Autowired 在一项测试中使用相同的服务 class - @MockBean and @Autowired of the same service in one test class 从 Spring Boot 集成测试运行原始应用程序 - Running the original application from Spring Boot integration test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM