In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the method of WeChat Mini Programs's unit test". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn "what is the method of WeChat Mini Programs unit testing"!
The next step after programming and implementation is unit testing. For the location alarm Mini Program, it is a necessary way to move around with the device to test the status transition of the monitoring point, but if all the links are solved through field testing, it will take a lot of time and energy.
Our choice is to do the unit test at as little cost as possible before the field test.
Test object
Our test object is the monitoring point state transition logic described in the previous article, that is, the enterAlarmCheck function in the lower-right corner of the above sequence diagram. This function can be said to be the core of this Mini Program. Its calling relationship is as follows.
The system calls the onTimer function of index (actually an unnamed function).
The onTimer function calls the checkAlarms function of app.
The checkAlarm function calls the checkAlarmsImpl function of app
CheckAlarmsImpl calls the util.getLocation function to get the current location information.
CheckAlarmsImpl gets the alarm of each monitoring point and calls the checkLocation method of alarm with the location information obtained by getLocation
The checkLocation method of alarm calls the getDistance method to get the distance from the current position to the monitoring point.
The enterAlarmCheck of alarm performs state transition processing based on the latest distance information.
Testing method
Among other things, the only testing difficulty here is location change, and we have adopted the simplest and roughest way: directly modify the getDistance method of alarm.
GetDistance: function (latitude, longitude) {
Var test =
[800, 700, 600, 500, 400, 300, 200, 100
90, 80, 70, 60, 50, 40, 52, 43, 53, 81, 101
201, 301, 401, 501, 502, 403, 304, 204, 105
96, 87, 78, 69, 50, 41, 42, 43, 54, 89, 100
110, 123, 145, 156]
If (this.testIndex < test.length) {
Return test [this.testIndex++]
} else {
Return 0
}
/ / return util.getDistance (this.latitude, this.longitude, latitude, longitude)
}
The original function of the function has been masked and directly modified to return the numbers in the array each time. We can simulate all kinds of motion by modifying the contents of the array.
You may think that modifying the uitl.getLocation function is also a way, but it has two problems: one is that the function may be called elsewhere, and the other is that the generated data must be latitude and longitude, which is troublesome.
In fact, the function getDistance is designed for unit testing.
Unit testing is a technical job.
Thank you for your reading. the above is the content of "what is the method of WeChat Mini Programs's unit test". After the study of this article, I believe you have a deeper understanding of what the method of WeChat Mini Programs's unit test is. The specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.