Maven POST和PUT的状态代码通过pom.xml mvn测试失败

Maven POST和PUT的状态代码通过pom.xml mvn测试失败,maven,post,put,rest-assured,Maven,Post,Put,Rest Assured,当我通过pom.xml运行testng.xml文件时,我的放心测试用例失败,POST和PUT API的错误状态代码为null。对于GET,它工作得很好 所用时间:0.066秒 如果不显示代码,就很难找出问题所在。请编辑您的问题并添加测试代码。已更新问题。问题是当我从pom.xml触发时,getStatusCode方法中的响应变量变为null。。因此,这可能是maven surefire插件的顺序问题。但通过testng.xml,不需要surefire。所以它运行我的测试用例。请帮助我解决此问题。

当我通过pom.xml运行testng.xml文件时,我的放心测试用例失败,POST和PUT API的错误状态代码为null。对于GET,它工作得很好

所用时间:0.066秒
如果不显示代码,就很难找出问题所在。请编辑您的问题并添加测试代码。已更新问题。问题是当我从pom.xml触发时,getStatusCode方法中的响应变量变为null。。因此,这可能是maven surefire插件的顺序问题。但通过testng.xml,不需要surefire。所以它运行我的测试用例。请帮助我解决此问题。两种测试方法中都存在名为
response
的变量,但我看不出它在哪里初始化。在哪里初始化它?在类本身中。我没有提到。让我更新这个问题。实际上,当它移动到下一个方法时,响应将变为null,即通过pom.xml获取getStatusCode()。但是从testng.xml直接命中效果很好。因此,maven surefire插件可能存在问题。它有一些不同的方法来运行任何测试。
public class CreateUser extends TestBase{

static Response response;

    @Test(priority=0, description="Create the user")
    public void createUser(){

        TestModelPojo testModel = new TestModelPojo();

        Primary prim = new Primary();
        prim.setFirstname(firstName);

        testModel.setPrimary(prim);
        testModel.setEmail(eMail);


    response = SerenityRest.given()
                .contentType(ContentType.JSON)
                .log()
                .all()
                .when()
                .body(testModel)
                .post("/customer/register")
                .then()
                .extract().response();

    }

    @Test(priority=1, description="Generate the status code as 201")
    public void getStatusCode() throws InterruptedException {   
        response.then().log().all().statusCode(201);
    }

}
public class TestBase {

    @BeforeClass
    public static void init() {
        RestAssured.baseURI  = "http://restapi.demoqa.com";
    }

}
<plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
               <source>1.8</source>
               <target>1.8</target>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
         </plugin>
      </plugins>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="2">
  <test thread-count="5" name="Test" preserve-order="true">
     <classes>
      <class name="com.demo.CreateUser"/>
    </classes>  

  </test> <!-- Test -->
</suite> <!-- Suite -->