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

时间:2019-01-12 07:15:26

标签: java testing junit pact contract

在创建契约验证测试时,我正在使用httpTarget方法。但问题是我的服务没有端口值。我们如何运行呢?请指教。 服务网址= 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",);

}

1 个答案:

答案 0 :(得分:0)

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