Skip to content
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

Unit Test suites for AsyncTasks #244

Merged
merged 10 commits into from
Aug 12, 2022

Conversation

sanyud24
Copy link
Contributor

@sanyud24 sanyud24 commented Jul 7, 2022

Tested custom AsyncTask classes.

package org.opendatakit.services.resolve.task

CheckpointResolutionListTask

  • Used Roboelectric ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED) to change the
    "card-status = mounted" and to set mock external storage.
  • Mockito to mock ResolutionListener class

ConflictResolutionListTask

@odk-x-bot
Copy link

Can one of the admins verify this patch? Also need an authorization to run tests.

@sanyud24
Copy link
Contributor Author

sanyud24 commented Jul 7, 2022

Hi @wbrunette @Lamouresparus , created the test for async task classes.

Copy link
Member

@wbrunette wbrunette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your setup creates a background task each time. Does the task run? What happens if you cancel the task? What about making sure the task finishes?

}

@Test
public void checkIfResolutionListener_isAvailable() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not seem to verify any behavior. Normally you see an assert to verify it's working

Copy link
Contributor Author

@sanyud24 sanyud24 Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a doubt in this one, I actually wanted to test if resolutionListener will set to null after calling clearResolutionListener according to the class behavior, but I can't cause it can't be accessed. Can I add a getResolutionListener() to test the functionality of these two functions?

public ResolutionListener getResolutionListener() { return rl; }

Screenshot from 2022-07-08 00-38-42


@Test
public void checkIfResolutionListener_isAvailable() {
conflictResolutionListTask.setResolutionListener(resolutionListener);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not seem to verify any behavior. Normally you see an assert to verify it's working

@sanyud24
Copy link
Contributor Author

sanyud24 commented Jul 7, 2022

Your setup creates a background task each time. Does the task run? What happens if you cancel the task? What about making sure the task finishes?

Yeah, ur right!! added the asynctask.execute to make sure task runs and asynctask.cancel to make sure asynctask thread stops.

@sanyud24
Copy link
Contributor Author

sanyud24 commented Jul 7, 2022

Hi @wbrunette, There's still the error of OdkConnectionFactorySingleton not initialized as it's a final class and mockito can't mock it. I'll look into the issue.

@wbrunette
Copy link
Member

@sanyud24 did you solve the issue on of the mockito?

@sanyud24
Copy link
Contributor Author

@sanyud24 did you solve the issue on of the mockito?

Yeah @wbrunette , I'm almost done with it.

@sanyud24
Copy link
Contributor Author

Hi, @wbrunette fixed this PR and added a base test class.

@wbrunette wbrunette merged commit f1c2804 into odk-x:outreachy-2022 Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants