当我通过pom.xml运行testng.xml文件时,我放心的测试用例失败,错误状态代码为POST和PUT API为null。对于GET,它工作正常。
经过的时间:0.066秒<<<失败! java.lang.NullPointerException
但是当我单独或通过testng.xml运行测试用例时,同样可以正常工作。
这是测试用例-
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);
}
}
TestBase类-
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>
testng.xml-
<?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 -->
请帮助我解决此问题。