我们需要对 Pact 中的 @TestTarget 变量做些什么吗?
Do we need to do something with the @TestTarget variable in Pact?
我目前正在学习 Pact,并且有一个关于 @TestTarget 注释的查询。要将 class 指向目标,我们必须使用 3 种目标类型(http、https 和消息)中的任何一种初始化变量,并在变量定义之前添加此 @TestTarget 注释。
但是在那之后我们需要对变量做些什么吗?还是它的使用结束了?
一旦我们以这种方式定义了一个 TestTarget,我们可以说在这个 class 中定义的所有 Pact 测试都会自动选择这个目标吗?
进口au.com.dius.pact.provider.junit.PactRunner;
导入 au.com.dius.pact.provider.junit.Provider;
导入 au.com.dius.pact.provider.junit.State;
导入 au.com.dius.pact.provider.junit.loader.PactFolder;
导入 au.com.dius.pact.provider.junit.loader.PactUrl;
导入 au.com.dius.pact.provider.junit.target.HttpTarget;
导入 au.com.dius.pact.provider.junit.target.Target;
导入 au.com.dius.pact.provider.junit.target.TestTarget;
导入 org.junit.Before;
导入 org.junit.BeforeClass;
导入 org.junit.ClassRule;
导入 org.junit.runner.RunWith;
进口java.net.URL;
导入 java.util.Map;
@RunWith(PactRunner.class) // 使用自定义 Runner 对 运行 测试说 JUnit
@Provider("getCountryService") // 设置测试提供者的名称
@PactFolder("../pacts") // 指出在哪里可以找到契约(另请参阅文档中的契约源部分)
//@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("http", "services.groupkt.com",);
}
- 不,只是声明
TestTarget
。 Pact 库将根据需要使用它。
- 是的,它会自动执行
我目前正在学习 Pact,并且有一个关于 @TestTarget 注释的查询。要将 class 指向目标,我们必须使用 3 种目标类型(http、https 和消息)中的任何一种初始化变量,并在变量定义之前添加此 @TestTarget 注释。
但是在那之后我们需要对变量做些什么吗?还是它的使用结束了?
一旦我们以这种方式定义了一个 TestTarget,我们可以说在这个 class 中定义的所有 Pact 测试都会自动选择这个目标吗?
进口au.com.dius.pact.provider.junit.PactRunner; 导入 au.com.dius.pact.provider.junit.Provider; 导入 au.com.dius.pact.provider.junit.State; 导入 au.com.dius.pact.provider.junit.loader.PactFolder; 导入 au.com.dius.pact.provider.junit.loader.PactUrl; 导入 au.com.dius.pact.provider.junit.target.HttpTarget; 导入 au.com.dius.pact.provider.junit.target.Target; 导入 au.com.dius.pact.provider.junit.target.TestTarget; 导入 org.junit.Before; 导入 org.junit.BeforeClass; 导入 org.junit.ClassRule; 导入 org.junit.runner.RunWith;
进口java.net.URL; 导入 java.util.Map;
@RunWith(PactRunner.class) // 使用自定义 Runner 对 运行 测试说 JUnit @Provider("getCountryService") // 设置测试提供者的名称 @PactFolder("../pacts") // 指出在哪里可以找到契约(另请参阅文档中的契约源部分)
//@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("http", "services.groupkt.com",);
}
- 不,只是声明
TestTarget
。 Pact 库将根据需要使用它。 - 是的,它会自动执行