maven+testng传参数

1.jenkins 有cookie参数要传入

 

Run:  clean test -Dcookie=$cookie

 

2.maven接收

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <systemPropertyVariables>
            <testEnvironment>${cookie}</testEnvironment>
        </systemPropertyVariables>
        <suiteXmlFiles>
            <suiteXmlFile>${xmlFileName}</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

 

 

3.testng接收

<suite name="AdSDK" thread-count="1">
    <parameter name="cookie" value="${cookie}" />
    <test name="AdSdkTest" preserve-order="true">

 

转载于:https://www.cnblogs.com/season-xie/p/7359592.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于 TestNG 和 Spring Boot,可以设计一套基于 JSON 据驱动的 API 测试框架。步骤如下: 1. 设计测试用例 在 JSON 文件中编写测试用例,包括测试 URL、请求方法、请求参数、请求头、预期响应状态码、预期响应结果等。 2. 编写测试代码 使用 TestNG 编写测试代码,读取 JSON 文件中的测试据,发送 HTTP 请求并验证响应结果。 3. 设计据驱动 在 TestNG 中,可以使用 DataProvider 注解实现据驱动。在据驱动方法中读取 JSON 文件中的据,返回一个二维组或者 Iterator 对象,作为测试方法的参数。 4. 集成 Spring Boot 使用 Spring Boot 框架,可以方便地管理测试环境、依赖注入等。在测试代码中,可以使用 Spring 的自动装配功能获取依赖对象,例如 RestTemplate、ObjectMapper 等。 5. 运行测试 使用 TestNG 运行测试,生成测试报告并输出结果。可以使用 Maven 或 Gradle 等构建工具自动化运行测试。 下面是一个示例代码: ```java @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class ApiTest { @Autowired private TestRestTemplate restTemplate; @Autowired private ObjectMapper objectMapper; @DataProvider(name = "testData") public Iterator<Object[]> testData() throws Exception { InputStream inputStream = getClass().getResourceAsStream("/test.json"); List<Map<String, Object>> testData = objectMapper.readValue(inputStream, new TypeReference<List<Map<String, Object>>>() {}); return testData.stream().map(data -> new Object[] {data}).iterator(); } @Test(dataProvider = "testData") public void testApi(Map<String, Object> data) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> request = new HttpEntity<>(data.get("request").toString(), headers); ResponseEntity<String> response = restTemplate.exchange(data.get("url").toString(), HttpMethod.valueOf(data.get("method").toString()), request, String.class); Assert.assertEquals(response.getStatusCodeValue(), (int) data.get("status")); Assert.assertEquals(response.getBody(), data.get("response")); } } ``` 在这个例子中,测试据保存在 test.json 文件中,使用 ObjectMapper 解析为 Map 对象。测试方法 testApi 读取 Map 对象中的测试据,发送 HTTP 请求,并验证响应结果。使用 Spring Boot 自动装配 RestTemplate,可以方便地发送 HTTP 请求。使用 TestNG 的 DataProvider 实现据驱动,可以重复执行测试方法,验证不同的测试据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值