-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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"))); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
Following tests are covered in this: