Serenity BDD:如何使用软断言循环执行步骤
Serenity BDD : How to loop on Steps with Soft Assertions
我需要 运行 测试一组数据,但我找不到在我的步骤中进行软断言并在 Serenity 报告中的正确步骤中显示错误的方法。
示例代码
@Then("All my datas are correct")
public void verifyMyDatas(){
int[] myDataArray = new int[] {1,2,3,4};
for(int i = 0; i < myDataArray.length; i++){
mySteps.myAwesomeValidator(myDataArray[i]);
}
}
还有一个示例步骤:
@Step("Checking the value {0}")
public void myAwesomeValidator(int value){
//I need a soft assertion here
}
我的尝试:
我尝试使用 assertj 框架。但我的问题是 "All my datas are correct" 步骤被正确标记为失败,但所有子步骤 "Checking the value X" 在 Serenity 的报告中都被标记为成功。
我的测试代码:
@Then("All my datas are correct")
public void verifyMyDatas(){
SoftAssertions softAssertion = new SoftAssertions();
int[] myDataArray = new int[] {1,2,3,4};
for(int i = 0; i < myDataArray.length; i++){
my mySteps.myAwesomeValidator(myDataArray[i], softAssertion);
}
softAssertion.assertAll();
}
以及步骤:
@Step("Checking the value {0}")
public void myAwesomeValidator(int value, SoftAssertions softAssertion){
softAssertion.assertThat(value < 3).isTrue();
}
编辑:试图通过我的尝试澄清问题
我会尝试 as()
来描述断言而不是引入 Step
以查看它是否有效(我相信它应该):
@Then("All my datas are correct")
public void verifyMyDatas(){
SoftAssertions softAssertion = new SoftAssertions();
int[] myDataArray = new int[] {1,2,3,4};
for(int i = 0; i < myDataArray.length; i++) {
myAwesomeValidator(myDataArray[i], softAssertion);
}
softAssertion.assertAll();
}
public void myAwesomeValidator(int value, SoftAssertions softAssertion){
// use as() to describe the assertion
softAssertion.assertThat(value)
.as("awesomely validate value %d", value);
.isLessThan(3);
}
我需要 运行 测试一组数据,但我找不到在我的步骤中进行软断言并在 Serenity 报告中的正确步骤中显示错误的方法。
示例代码
@Then("All my datas are correct")
public void verifyMyDatas(){
int[] myDataArray = new int[] {1,2,3,4};
for(int i = 0; i < myDataArray.length; i++){
mySteps.myAwesomeValidator(myDataArray[i]);
}
}
还有一个示例步骤:
@Step("Checking the value {0}")
public void myAwesomeValidator(int value){
//I need a soft assertion here
}
我的尝试:
我尝试使用 assertj 框架。但我的问题是 "All my datas are correct" 步骤被正确标记为失败,但所有子步骤 "Checking the value X" 在 Serenity 的报告中都被标记为成功。
我的测试代码:
@Then("All my datas are correct")
public void verifyMyDatas(){
SoftAssertions softAssertion = new SoftAssertions();
int[] myDataArray = new int[] {1,2,3,4};
for(int i = 0; i < myDataArray.length; i++){
my mySteps.myAwesomeValidator(myDataArray[i], softAssertion); }
softAssertion.assertAll();
}
以及步骤:
@Step("Checking the value {0}")
public void myAwesomeValidator(int value, SoftAssertions softAssertion){
softAssertion.assertThat(value < 3).isTrue();
}
编辑:试图通过我的尝试澄清问题
我会尝试 as()
来描述断言而不是引入 Step
以查看它是否有效(我相信它应该):
@Then("All my datas are correct")
public void verifyMyDatas(){
SoftAssertions softAssertion = new SoftAssertions();
int[] myDataArray = new int[] {1,2,3,4};
for(int i = 0; i < myDataArray.length; i++) {
myAwesomeValidator(myDataArray[i], softAssertion);
}
softAssertion.assertAll();
}
public void myAwesomeValidator(int value, SoftAssertions softAssertion){
// use as() to describe the assertion
softAssertion.assertThat(value)
.as("awesomely validate value %d", value);
.isLessThan(3);
}