0

I am very trying the pact-jvm-provider-junit using IntelliJ IDEA as my IDE.

I'm testing out the provided ContractTest example:

import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.ClassRule;

import au.com.dius.pact.provider.junit.State;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit.target.TestTarget;
import au.com.dius.pact.provider.junit.target.Target;
import au.com.dius.pact.provider.junit.target.HttpTarget;
import au.com.dius.pact.provider.junit.TargetRequestFilter;

import org.apache.http.HttpRequest;


import au.com.dius.pact.provider.junit.PactRunner;
import au.com.dius.pact.provider.junit.loader.PactFolder;
import au.com.dius.pact.provider.junit.loader.PactUrl;
import au.com.dius.pact.provider.junit.VerificationReports;

import com.github.restdriver.clientdriver.ClientDriverRule;

import org.junit.runner.RunWith;
import org.slf4j.LoggerFactory;

import org.slf4j.Logger;

import static com.github.restdriver.clientdriver.RestClientDriver.giveEmptyResponse;
import static com.github.restdriver.clientdriver.RestClientDriver.onRequestTo;



@RunWith(PactRunner.class) // Say JUnit to run tests with custom Runner
@Provider("uicc_repository") // Set up name of tested provider
//@PactFolder("rs") // Point where to find pacts (See also section Pacts source in documentation)
@PactUrl(urls = {"file:///C:/IdeaProjects/src/pack-test-provider/resources/test_consumer-test_provider.json"}) // Point where to find pacts (See also section Pacts source in documentation)
@VerificationReports(value = {"markdown","json"}, reportDir = "C:/IdeaProjects/src/pack-test-provider/resources")

public class ContractTest {


    // NOTE: this is just an example of embedded service that listens to requests, you should start here real service
    @ClassRule //Rule will be applied once: before/after whole contract test suite
    public static final ClientDriverRule embeddedService = new ClientDriverRule(6060);
    private static final Logger LOGGER = LoggerFactory.getLogger(ContractTest.class);

    @BeforeClass //Method will be run once: before whole contract test suite
    public static void setUpService() {
        //Run DB, create schema
        //Run service
        //...
    }

    @Before //Method will be run before each test of interaction
    public void before() {
        // Rest data
        // Mock dependent service responses
        // ...
        embeddedService.addExpectation(
                onRequestTo("/data"), giveEmptyResponse()
        );
    }

    @TestTarget // Annotation denotes Target that will be used for tests
    public final Target target = new HttpTarget(6060); // Out-of-the-box implementation of Target (for more information take a look at Test Target section)

    @State("default") // Method will be run before testing interactions that require "default" or "no-data" state
    public void toDefaultState() {
        // Prepare service before interaction that require "default" state
        // ...
        System.out.println("Now service in default state");
        LOGGER.info("Now service in default state");
    }
}

But when I try to run the test (Run -> Run ContractTest), it's like the test is not ran at all:

Mar 15, 2017 3:24:00 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines INFO: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage] Mar 15, 2017 3:24:01 PM org.junit.vintage.engine.execution.TestRun lookupTestDescriptor WARNING: Runner au.com.dius.pact.provider.junit.PactRunner on class rs.ContractTest reported event for unknown Description: rs.ContractTest. It will be ignored.

Process finished with exit code 0

enter image description here

I am not sure if it's an issue with how I am running the test in IntelliJ or I am missing something in the pact-jvm-provider "runner".

Appreciate any help on this topic.

Thanks!

ndelacrz
  • 1
  • 1
  • Have a look at https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-consumer-junit#using-the-pact-junit-rule, in special, there is a already predefined PactProviderRule – Markus Schulte Mar 22 '17 at 08:42
  • Also, it looks like you are trying to run the test using JUnit5, which is not currently supported. Set JUnit to version 4, and then try re-run the test. – Ronald Holshausen Apr 24 '17 at 00:45

0 Answers0