I'm new to Espresso in Android Studio. The app I'm testing sends information to a REST service which creates and sends back an ID number. In another piece of the app I can request that ID number and get its information back. I want to store the ID returned when created and insert it into the requester to verify it is created. I've found some Espresso methods which can get a string from a view, but it warns that that is dangerous and likely not the best way to do that. how to get text from textview using espresso
Can someone explain the best way to accomplish this task if getting a string is not a good idea? Or, is that the only way to do it?
The question is if a instrumentation test is really what you want to do in your case. If something is testable in a easy way depends on your architecture. Large integration tests tend to break often as they hold many dependencies - consider to write unit tests first and https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html is also a good read regarding that topic.
Related
I've implemented an ErrorHandler class into my app which is working just great but as I'm not sure if what I'm doing can fit into "best practices" just would like to share it with you to have your opinion.
My question is silly and my class is very simple. All that I do is the next: in every catch block of my whole java code I do a call to ErrorHabdler.log(e) (which works as an AsyncTask) and as I'm working with AWS what log(e) does is capture all information about the error, like message, device name and model, etc (NO user information) and sends a formatted email with the error to a specific email address.
Another possibility would be to create a new table into my AWS DynamoDB set called Exceptions and instead of sending an email in background write the error log into that new table to have errors more "centralized".
I'd like to know if you consider what I'm actualli doing a good practice, or if you prefer my second choice, or maybe none of them and you would better use a third party error logger.
Best!
There are several Crashlytics tools on the internet.
The best choice is to go to these tools, which make it easier to control crashes reports.
The most common, and is what I use in most of my projects, is Frabric.IO Crashlytics ,: https://fabric.io/kits/android/crashlytics
You can follow these steps to install Crashlytics in your project: https://fabric.io/kits/android/crashlytics/install
The Situation
I'm writing a timetable-viewing application and the first feature to be implemented is choosing the course for which to view the timetable.
The user chooses the name of their course from a list and is taken to another screen to further specify which year, group etc. of the course they're currently in. The screens to choose your course and edit your course details are as follows:
The Goal
Inspired by the Google I/O 17 talk on Test-Driven Development on Android, what I wish to write is a UI test case to test this feature. Specifically, I want my test to confirm that if the user clicks on one of the course names they will be taken to the 'edit course details' screen and that the course title at the top e.g. 'Accounting and Finance' matches the one that was clicked in the list.
The Problem
The test, using Espresso, for the specific case of choosing the course titled 'Accounting and Finance' and seeing if the correct title shows up on the next screen, would look (roughly) like this:
#Test
public void chooseCourse() {
onView(withId(R.id.rv_course_list))
.perform(RecyclerViewActions.actionOnItemAtPosition(
/*Somehow find position of Accounting and Finance*/,
click())
);
onView(withId(R.id.course_title))
.check(matches(withText("Accounting and Finance")))
.check(matches(isDisplayed()));
}
My problem is that the RecyclerView course list will be populated using results from a HTTP request or a SQLite database at runtime and there is no way of knowing beforehand whether the list will contain 'Accounting and Finance' or something else (I don't want the test to fail just because a specific course isn't in the list when the application runs).
Taking this into consideration I cannot hard-code the course name into the test. Please note that I'm not trying to write a unit test where I would just mock the dependency of obtaining the course list to ensure that 'Accounting and Finance' is in the list (and would probably just isolate the ChooseCourseActivity class, capturing its Intents).
In the video I linked to above, the presenter talks us through a UI test of the add-note feature of a notes application where the test is as follows:
Click on the 'add note' button
Enter title and description of the note
Click on the 'save note' button
Verify that a new note with the details from step 2 is contained in the list
In that scenario hard-coding the text (title and description) used to find the views works great because the code in the test determines the contents of the view i.e. the note in the notes list. In my case, the contents of the view will be determined by a HTTP response or db query
The Question
How do I write an adequate UI test for the choose-course feature before implementing it?
Is the method used in the video to test the notes app simply not applicable to my feature (because I cannot hard-code the course title that is to be chosen from the list)?
Am I just misunderstanding UI testing and should be mocking dependencies (even though the speaker in the video did not)?
Edit: The best solution to this problem seems to be what is called 'hermetic testing' and this blog describes how to apply it to android UI.
You can test this in a few different ways and I've used a combination of all of them within my apps.
1) You can mock your network/database layer as you suggested.
2) You can make a call to your API in your test to get your 'expected' data set and then verify that it appears correctly in your UI.
3) You can Stub your networking layer to allow you to inject known data and not rely on your networking endpoint. Retrofit in particular makes it very easy to do this.
4) You can test against live endpoints using a known test dataset that won't change frequently.
I tend to use Espresso both for UI level tests and full blown regression tests. In the UI level tests, I stub out the networking/on device persistence layer and just test the client side with datasets that I inject during the test. For regression tests, I care about testing the integration with my API and for those I use a testing account that has known unchanging data.
The situation: I have many real life locations with specific information associated with them, and updated frequently. I am unsure of how to store this information for use in an android application.
My original thought was storing the data on some server/cloud source/database, reading from the server from each Activity in the app to make sure the info is up to date, and update the server with any changes that may or may not have been made.
For example: there are 200 people inside the library, one person leaves.
So we would read the number of people from the server, display this on the app, person leaves, subtract one, send the new number back to the server.
Would this be an incorrect approach? I'm fairly new to Android in general, and I really have no experience on how to approach this type of situation, what services to use, etc.
I would look into using Parse, its a pretty sweet way to power the backend, and their website is very detailed in explaining how to use it.
I am looking into options how to realize the following use case. A iOS/Android user is using my app which gets its table view data populated by a cloud database solution. The user must be able to send back information (e.g. name + date) which needs to be send back to the database and gets stored there in a/different table/s. Moreover, I would need the db-solution to run automated reports based on the information sent back by the users (e.g. in an excel file).
So far I only found ragic.com might suit my needs. But what other options are out there, which might not be as fancy looking but will get the job done. Thanks guys!
A WebService is considered best practice regarding these matters. Have a look at this guys tutorial:
http://android.programmerguru.com/android-webservice-example/
This is a question about Application design rather than how-to-do specific actions.
I am a student taking a beginner's course in Android Development. I am designing a program which initially requires the person to login, then at a later time they may choose to display a record of all the users that have logged in previous sessions.
As of right now, there are two parts of my app: LoginField Activity which takes the login data from the EditText field, and which is then supposed to write that information to an external .dat file of some kind so that the information will persist across launches, and a LoginHistory Activity which is supposed to display this history in a ListView.
I have toyed with creating a separate class for the ArrayAdapter logic - an ArrayAdapterController class (?) - but was uncertain how to pass information back and forth between it and the two Activities.
so - my questions are these:
since the information needs to persist across sessions what is the
best method to do this? it does not have to be secure for the moment
as this is only a student project.
does it make sense to make a separate Controller class to handle the information that will be passed between Views/Activities?
apologies for the general nature of this question - as you can see I am an MVC novice.
You've asked a general question, so the best I can do is give you a general answer. You want to use the AbstractAccountAuthenticator class. The documentation there should give you a good jumping off point for you. Furthermore, the SampleSyncAdapter provides a comprehensive (but complex) example of using the authenticator with a full on REST Web Service.