testNG分组执行的时候报错depends on nonexistent method “xxxx.xxxxx“

错误的代码:

package pro.data;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

import pro.assertion.MyAssert;

//sb124--jenkis
public class AddFund {
	CloseableHttpClient client = null;
	CloseableHttpResponse response = null;
	MyAssert assertion = new MyAssert();
	private int i = 5;


	@Parameters({ "myNumber" })
	public AddFund(@Optional("5") int i) {
		this.i = i;
	}

	@BeforeClass
	public void beforeClass() {
		client = HttpClients.createDefault();
		System.out.println("beforeClass-hc");
	}

	@Test(testName = "login")
	public void login() {
		System.out.println("i 先登录");
	}

	@Parameters({ "myNumber" })
	@Test(dependsOnMethods = {"login" }, groups = { "ga" })
	public void add(String userId, String fundCode, String fundName, String holdPortion) {
		System.out.println("执行第" + i + "次");
		String content = "";
		HttpGet request = new HttpGet("http://localhost:9999");
		try {
//			此处可以解决中文乱码
			fundName = URLEncoder.encode(fundName, "utf-8");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		String path = "/addFundRpWithParams?userId=" + userId + "&fundCode=" + fundCode + "&fundName=" + fundName
				+ "&holdPortion=" + holdPortion;
		request.setPath(path);
		try {
			System.out.println(request.getRequestUri());
			response = client.execute(request);
			HttpEntity entity = response.getEntity();
			content = EntityUtils.toString(entity, "utf-8");
			// System.out.println(content);
		} catch (Exception e) {
			e.printStackTrace();
		}
		assertion.assertEquals(content.contains("成功"), true);
		assertion.assertAll();
	}
	@Test(groups= {"gb"})
	public void pr() {
		System.out.println("当前线程id:"+Thread.currentThread().getId());
	}

}
<test name="add-fund" group-by-instances="true">
		<packages>
			<package name="pro.data" />
		</packages>
		<groups>
			<run>
				<include name="ga" />
			</run>
		</groups>
</test>

可以看出方法add所在的组为“ga",并且依赖方法login,不过login并未处在任何分组中,通过xml执行的时候,login方法不在执行范围,所以导致org.testng.TestNGException--depends on nonexistent method "pro.data.AddFund.login" 错误

解决办法:

只要将依赖的放也放进被执行的组中即可

	@Test(testName = "login",groups = { "ga" })
	public void login() {
		System.out.println("i 先登录");
	}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值