如何在使用 PACT 时在 httptarget 方法中传递 url

how to pass url in httptarget method while using PACT

在创建契约验证测试时,我正在使用 httpTarget 方法。但问题是我的服务没有端口值。我们怎么能运行这个?请指教。 服务 URL=http://services.groupkt.com/country/get/iso3code/IND

下面是我的验证测试。 包裹 se.ff.bsv;

import au.com.dius.pact.provider.junit.PactRunner;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit.State;
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.target.HttpTarget;
import au.com.dius.pact.provider.junit.target.Target;
import au.com.dius.pact.provider.junit.target.TestTarget;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.runner.RunWith;

import java.net.URL;
import java.util.Map;

@RunWith(PactRunner.class) // Say JUnit to run tests with custom Runner
@Provider("getCountryService") // Set up name of tested provider
@PactFolder("../pacts") // Point where to find pacts (See also section Pacts source in documentation)

//@PactUrl(urls = {"http://services.groupkt.com/country/get/iso3code/IND"} )

public class getCountryContractTest {

    @State("There is a country with alpha2_code as IN having name as India") // Method will be run before testing
                                                                                // interactions that require "with-data"
                                                                                // state
    public void hammerSmith() {
        System.out.println("There is a country with alpha2_code as IN having name as India");
    }

    @TestTarget // Annotation denotes Target that will be used for tests

    //public final Target target = new HttpTarget(8111);// Out-of-the-box implementation of Target (for more information take a look at Test Target section)
    public final Target target = new HttpTarget("http", "services.groupkt.com",);

}

你不能说你的服务没有端口,但你可以说你的服务使用默认端口(例如)。在这种情况下,请尝试使用端口 80。