[英]Flutter: unit testing
I'm trying to test this function: 我正在尝试测试此功能:
setToday(Map filters) {
if (filters['today'] == false) {
filters['yesterday'] = false;
filters['lastWeek'] = false;
filters['lastMonth'] = false;
filters['customRange'] = false;
filters['today'] = true;
} else
filters['today'] = false;
}
And this is the test: 这是测试:
test("", (){
Map<String, bool> filters = {
"today" : false,
"yesterday" : false,
"lastWeek" : false,
"lastMonth" : false,
"customRange" : false,
};
expect(_kpiFilterViewController.setToday(filters), filters["today"] == true);
});
But the result is : 但是结果是:
Expected: <true>
Actual: <null>
What is my mistake? 我怎么了
Function under test does not return anything, so calling 被测函数不返回任何内容,因此调用
_kpiFilterViewController.setToday(filters)
in the expect
assertion will fail. expect
断言将失败。
test("filters[today] value should be true", () {
//Arrange
Map<String, bool> filters = {
"today" : false,
"yesterday" : false,
"lastWeek" : false,
"lastMonth" : false,
"customRange" : false,
};
bool expected = true;
//Act (call the method under test)
_kpiFilterViewController.setToday(filters);
//Assert (verify expected behavior)
bool actual = filters["today"];
expect(actual, expected);
});
Reference Flutter: Introduction to unit testing 参考Flutter:单元测试简介
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.