简体   繁体   中英

How to run the test files by using the testng.xml

项目结构

I have created a project as per the above package structure and I'm facing an issue on running the test's by the testng.xml file I manually created.

All the test classes reside in their own packages under the API package, and the API package consists of each module of the application as packages where test classes are defined in their respective module packages.

In the attached screenshot im referring only one package to be run from the testng.xml file and when running the file it displays as "No tests were found"

below is a code segment of ApprovalGroupManagementApi.class where the test methods are in with propper TestNG annotations.

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);
        }
    }


}

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

<!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>

Please try this It might help you to execute testng class. (Apart from this also make sure the plugin of testng is already installed.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM