New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetStorage strange behaviour in unit tests #37
Comments
I have added another test and now it looks like the StorageData updates from the second test made their way into the first test and both are failing test code
I tried erasing the storage before I run the update or at the end of the test, but it throws an exception in both cases:
|
@jonataslaw can you take a look at this issue? |
Initially, you need to mock the storage (look at the testing example in the repository). Your code should look something like this: const channel = MethodChannel('plugins.flutter.io/path_provider');
void setUpMockChannels(MethodChannel channel) {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'getApplicationDocumentsDirectory') {
return '.';
}
});
}
setUpAll(() async {
setUpMockChannels(channel);
|
@jonataslaw when you say mock the storage per testing example, do you mean this?
I am using a shared preferences implementation of GetStorage, so the storage is a private member of StoredUserData class. Are you saying I need to expose it? or is the below sufficient:
I've added the storage configuration code you posted above, but still getting the errors: FileSystemException: Cannot delete file, path = 'C:...\Documents/UserData.gs' (OS Error: The process cannot access the file because it is being used by another process. |
I inserted above exactly the missing code snippet in your application, just copy and paste. |
I did, still same problem |
Impossible give "'C:...\Documents/UserData.gs'" error, since this path is not be used with example above |
I did flutter clean, but still getting this error. below is my updated code with your snippet. Click To Expand
|
@jonataslaw , did not get a response from you on the above, please let me know |
@jonataslaw I like your plugins, you did a great job creating them, but I unfortunately I cannot keep using them if they are not testable. I understand you are supporting them by yourself, but 16 days no response seems a little excessive |
I think this issue can be closed, because when mock the storage with the right way like the repository example, the tests works. |
I never was able to get it to work as per my comments above and eventually had to stop using the plugin. It's up to you to close it or not |
Exactly, even when I copy exactly the test of the package in my test I even get the same error, so Unfortunately I should say it is not testable at all. |
I am writing unit tests for my implementation of GetStorage shared preferences alongside GetX and it would be so helpful to see how to properly use both GetStorage and GetX controllers in unit tests.
I see some very inconsistent GetStorage behaviour in my unit tests - sometimes the data gets updated, other times not and most of the time the data persists until another test is run, even though I initialize the class from scratch every time .
The unit test does not pick up the correct values inside the variables. For example, both userData.firstName.val, errorController.contactInfoMissing.value inside the test even though I confirmed they are both being set with correct values in the code. This leads me to believe that I may doing something wrong inside the unit test, but there is no documentation on how to do it properly.
P.S. StoredUserData works fine in my app, but for some reason not in the unit test.
Also, I wasn't able to initialize the ErrorController inside the setUp of the unit test. StoredUserData is not finding it in this case, therefore I had to initialize it in the test itself - not sure if proper.
Unit test code
Code being tested:
The text was updated successfully, but these errors were encountered: