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

Adds unit tests for DBHandler and MainActivity. #33

Merged
merged 3 commits into from
Jul 20, 2019

Conversation

DreamyPhobic
Copy link
Collaborator

Following tests are covered in this:

  1. SQLite Database communications test
  2. Test for connection with ODK Services Database
  3. QRCode Scanner Test

Copy link
Member

@linl33 linl33 left a comment

Choose a reason for hiding this comment

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

Overall this is a good start. There are just a few minor things. Keep adding more tests and soon we will have a robust test suite.

In the DBHandlerTest, there should be a @Before or @After method that cleans the db to prevent potential interaction between the tests. In general, it is a good idea to make sure the environment in which tests start in is consistent and predictable.

Another thing that will be a problem, but don't worry about it now, is setting up ODK-X Services for the tests. Since Services needs read/write external storage permissions, they need to be granted before the tests start.

public class MainActivityTest {

@Rule
public GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant("android.permission.CAMERA");
Copy link
Member

Choose a reason for hiding this comment

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

The string literal can be replaced by Manifest.permission.CAMERA

public void qrCodeIntentTest(){
onView(withId(R.id.fab)).perform(click());
intended(allOf(
hasAction("com.google.zxing.client.android.SCAN")));
Copy link
Member

Choose a reason for hiding this comment

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

This literal can be replaced by this constant


@Before
public void setUp(){
dbHandler = new DBHandler(InstrumentationRegistry.getTargetContext(),null,null,1);
Copy link
Member

Choose a reason for hiding this comment

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

getTargetContext is deprecated, check the javadoc for replacement.

import static org.hamcrest.core.AllOf.allOf;

@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
Copy link
Member

Choose a reason for hiding this comment

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

This is a test that interacts with the UI, it is a good practice to annotate it with @LargeTest

public class MainActivityTest {

@Rule
public GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant("android.permission.CAMERA");
Copy link
Member

Choose a reason for hiding this comment

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

The MainActivity also needs READ_EXTERNAL_STORAGE

@DreamyPhobic
Copy link
Collaborator Author

@linl33 @jbeorse I've made the required changes.

@linl33 linl33 merged commit f6a426b into odk-x:master Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants