【发布时间】:2023-03-28 00:19:01
【问题描述】:
我在 List() 类型的单独类中有两个方法。两者都返回列表,但是在我的测试中,我想断言这两种方法的结果。这两种方法都在一个名为 navigate 的类中。我的断言语句不起作用:( - 如果值相同,我希望我的测试失败,如果值不同,我希望测试通过
public List<Integer> methodA() {
List<Integer> overallDurationAndTimeAfterWayPoint = new ArrayList<>();
if (routeOptions.size() != 0) {
for (int i = 0; i < routeOptionDescriptions.size(); i++) {
overallDurationAndTimeAfterWayPoint.add(Integer.parseInt(routeOptionDescriptions.get(i).getText()
.replaceAll("[^\\d.]", "").trim()));
overallDurationAndTimeAfterWayPoint.add(Integer.parseInt(routeOptionTravelTimes.get(i).getText()
.replaceAll("[^\\d.]", "").trim()));
}
}
return overallDurationAndTimeAfterWayPoint;
}
public List<Integer> Method B() {
List<Integer> overallDurationAndTimeAfterWayPoint = new ArrayList<>();
if (routeOptions.size() != 0) {
for (int i = 0; i < routeOptionDescriptions.size(); i++) {
overallDurationAndTimeAfterWayPoint.add(Integer.parseInt(routeOptionDescriptions.get(i).getText()
.replaceAll("[^\\d.]", "").trim()));
overallDurationAndTimeAfterWayPoint.add(Integer.parseInt(routeOptionTravelTimes.get(i).getText()
.replaceAll("[^\\d.]", "").trim()));
}
}
System.out.println("After " + overallDurationAndTimeAfterWayPoint);
return overallDurationAndTimeAfterWayPoint;
}
Assert.assertTrue(navigate.MethodA().equals(navigate.MethodB()));
【问题讨论】:
-
你的意思是
assertFalse(navigate.MethodA().containsAll(navigate.MethodB()) /*&& vice versa!?*/);!?
标签: java selenium arraylist automation