我对集成测试有一些疑问(OPA5,sapui5):我创建了简单的项目,它有2个视图(View1.view.xml和View2.view.xml),我在第一个上有sap.m.Button视图。按下此按钮后,我将导航到第二个视图。所以我已经实施了OPA5测试来检查这个功能。现在,我正在模拟用户点击按钮,导航工作正常。但是如果我想在触发导航后检查可见性View1.view.xml,我会得到"测试通过"结果!我猜测试是异步执行的,这就是我得到这个结果的原因。我怎样才能看到测试完成后续执行的时刻?
UnexpectedbehaviorJourney.js
QUnit.module("Unexpected behavior");
opaTest("Why do I see View1.view after Navigation was pressed?",
function (Given, When, Then) {
// Arrangements
Given.iStartMyApp();
//Actions
When.onTheAppView.iLookAtTheScreen().
and.iPressNavigateButton();
// Assertions
Then.onTheAppView.iShouldSeeView1AfterTriggeringNavigation();
// and.iTeardownMyAppFrame();
});
UnexpectedBehavior.js
actions : {
iPressNavigateButton : function () {
return this.waitFor({
id : "idButton",
viewName : "View1",
actions: new Press(),
errorMessage : "Button control wasn't pressed"
});
}
},
assertions : {
iShouldSeeView1AfterTriggeringNavigation : function () {
return this.waitFor({
id : "idView1",
viewName : "View1",
success : function () {
ok( true, "Why I can see View1.view?");
},
errorMessage : "Navigation has worked as expected!"
});
}
}
View1.controller.js
return Controller.extend("InvestigateOPA.controller.View1", {
onPress: function() {
this.getOwnerComponent().getRouter().navTo("appView2");
}
});
您是否知道如何防止此行为?
答案 0 :(得分:0)
断言是否应该检查View2的可见性?
其他尝试类似下面的内容
NB。您可以使用Qunit和Sinon函数,如延迟/计时器或本机承诺等。
iShouldNotSeeView1AfterTriggeringNavigation : function () {
return this.waitFor({
id: "app",
viewName: "App",
check: function(oApp) {
return oApp.getCurrentPage().getId() !== "__component0---View1"
},
success: function() {
ok( true, "View1 not current page");
},
errorMessage: "Navigation has not worked as expected!"
});
答案 1 :(得分:0)
我发现解决问题的一种方法是将“transition”属性设置为“show”:
public void TestObservableCollectionSortExtension()
{
var observableCollection = new ObservableCollection<int>();
var maxValue = 10;
// Populate the list in reverse mode [maxValue, maxValue-1, ..., 1, 0]
for (int i = maxValue; i >= 0; i--)
{
observableCollection.Add(i);
}
// Assert the collection is in reverse mode
for (int i = maxValue; i >= 0; i--)
{
Assert.AreEqual(i, observableCollection[maxValue - i]);
}
// Sort the observable collection
observableCollection.Sort((a, b) => { return a.CompareTo(b); });
// Assert element have been sorted
for (int i = 0; i < maxValue; i++)
{
Assert.AreEqual(i, observableCollection[i]);
}
}
在这种情况下,当一个视图改变另一个视图时没有视觉延迟,因此我的OPA测试将正常工作。 附:很多你的想法!