I am writing a Flutter plugin that checks the Play Store or App Store to see if the app needs to be updated. I'm using the package_info
package to determine the version of the app that the user has. My code looks like this:
getVersionStatus() {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
localVersion = packageInfo.version;
...
}
I want to test this method, but if it run it as a unit test the fromPlatform
call just hangs and times out the test. Is there a more elegant way to solve this than passing in a testing
boolean? I.e:
if (testing) {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
localVersion = packageInfo.version;
} else {
localVersion = '0.0.0'
}
Should the package_info
package provide a way to catch errors? Is there a way to tell if the method is being run by a test?