Pact framework - running one test only

Viewed 34

I wrote a provider test class using PACT, that has two tests. 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. Any ideas as how could I run in IntelliJ one test only? Provider test 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)
1 Answers

From what I know, the only way to verify specific interactions is to use @PactFilter

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). For static ones you can hardcode the values in your @PactFilter annotation.

Also just to add to your question regarding @State… States are in general similar to a @Before block. They don’t execute any tests but sets up the app for you in a desired state.

Hope this helps!

Related