0

项目结构

我已经根据上述包结构创建了一个项目,并且在通过手动创建的testng.xml文件运行测试时遇到了问题。

所有测试类都驻留在API包下它们自己的包中,API包由应用程序的每个模块作为包组成,其中测试类在各自的模块包中定义。

在随附的屏幕截图中,我仅引用了要从testng.xml文件运行的一个包,并且在运行该文件时,它显示为“未找到测试”

下面是ApprovalGroupManagementApi.class的代码段,其中测试方法带有适当的TestNG注释。

package com.api.approval_group_management;
import com.base.Base;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.javafaker.Faker;
import com.payloads.request.classes.CreatedUserList;
import com.payloads.request.classes.StatusList;
import com.payloads.request.payload.SecCreateApprovalLevel;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.testng.annotations.Test;
import org.testng.asserts.Assertion;
import org.testng.asserts.SoftAssert;
import java.util.ArrayList;
import java.util.List;
import static com.utils.Constant.SEC_CREATE_APPROVAL_LEVEL_URL;
import static io.restassured.RestAssured.given;

public class ApprovalGroupManagementApi extends Base {

    SoftAssert softAssert = new SoftAssert();
    Assertion hardAssert = new Assertion();

    @Test(priority = 1, alwaysRun = true, enabled = true)
    public void secCreateApprovalLevel() {
        try {

            ObjectMapper objectMapper = new ObjectMapper();
            SecCreateApprovalLevel secCreateApprovalLevel = new SecCreateApprovalLevel();
            StatusList statusList = new StatusList();
            CreatedUserList createdUserList = new CreatedUserList();
            List<Object> objects = new ArrayList<>();

            secCreateApprovalLevel.setName("" + new Faker().name().firstName());
            secCreateApprovalLevel.setApprovalLevelAvailable(true);
            secCreateApprovalLevel.setStatusList(statusList);
            secCreateApprovalLevel.setCreatedUserList(createdUserList);
            secCreateApprovalLevel.setPrivilageList(objects);

            String approvalGroup = objectMapper.writeValueAsString(secCreateApprovalLevel);

            RestAssured.useRelaxedHTTPSValidation();
            Response response = given().spec(resourceApiRequestSpecification).log().all()
                    .contentType(ContentType.JSON)
                    .when()
                    .body(approvalGroup)
                    .post(SEC_CREATE_APPROVAL_LEVEL_URL);

            //response code assertion
            hardAssert.assertEquals(response.getStatusCode(), 200);
            softAssert.assertAll();

        } catch (Exception e) {
            System.out.println(e);
        }
    }


}
4

2 回答 2

1

将包名更改为name="com.api.approval_group_management"testng.xml

于 2020-09-20T11:40:42.303 回答
0
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="suite 1">
    <test name="Regression 1">
        <classes>
            <class name="test.java.com.api.approval_group_management.ApprovalGroupManagementApi" />
        </classes>
    </test>
</suite>

请试试这个它可能会帮助你执行 testng 类。(除此之外还要确保已经安装了 testng 的插件。)

于 2020-09-20T10:21:39.630 回答