I want to write an Androidx test that starts an Application, waits for it to crash, and then starts it again.
As I understand it, by default, AndroidX tests run on a instrumentation, and when one test crashes, the entire instrumentation is brought down with it.To prevent one test from crashing the whole test suite, AndroidX includes an AndroidTestOrchestrator. This allows each test to run in its own instrumentation, so one test crashing only brings down the instrumentation it is in.
Given what I am trying to do, it looks like I will need to create my own AndroidTestOrchestrator to run a test with two instrumentations, one to run the Application crash, and then another to see that it is recovered from correctly.
How feasible is this?
Related
I would like to write an Espresso test that I can run on an application from outside that application. I don't have much experience with Android, but, as I understand it, a UI test is generally written and executed from inside the project of the application that it is supposed to test. For instance, according to the file explorer in Android Studio, the java files for a test application I was developing are stored in com.package.example.name, and the java files for the UI test are stored in com.package.example.name (androidTest).
I want to develop a UI test for an application (Application A) for which I do not have the project files. As I do not have the project for Application A, I cannot develop the test for Application A from inside that same project like I normally would. Thus, I have to somehow create and run it from outside.
My initial thought was to create a test application (Application B) from scratch and add a button to it that, when pressed, will open Application A. I would develop an Espresso test from inside Application B, have it press that button to launch Application A, and then have it follow other Espresso instructions I would develop by viewing the R.ids of Application A's UI elements through uiautomatorviewer.bat, included in the Android SDK tools.
At least to me, this seemed like it would work just fine in theory, so I went forward with the plan. However, when the button inside Application B is pressed by the UI test and Application A launches, the test cannot find an activity to continue testing on. No error is explicitly thrown; Logcat prints messages like "W/RootViewPicker﹕ No activity currently resumed - waiting: 2000ms for one to appear," repeatedly, where 2000ms increases as time goes on.
Historically, I have not had any problems when running Espresso tests across activity changes. I assume this issue has something to do with the fact that the activity being launched exists outside of the project where the Espresso test is based.
If anyone knows of a way to get an Espresso test to run successfully on an application when based in a project located outside of that application, I'd appreciate any advice you may be able to offer. I think I'm on the right track, but I don't know for sure. Thanks!
So i recently started using Robotium for the first time and noticed after some time that they are Executed in an alphabetical order. This made some test not work, because i needed the "introduction" of my app to be finished and than start other tests.
Since i have never used Automated tests before, im not sure how to write the tests right now. Should all the test cases ALWAYS be independent from each other?
This would mean in my case, that the flag for the introduction should be set false for some tests and true for other tests programmatically.
Or is it also right to assume that one test case has been Executed before another one?
This is correct. You should always build tests so they can run independently. Also take note to ensure you have a rollback process after running your tests. Otherwise the next time they might not run.
There is a lot to consider when writing automated tests.
I would say yes. All tests should always be independent from each others. That way your sure that another test is not the reason for the failing test case.
I run my Espresso test via Spoon. Often, I get a build successful, with tests not being executed. I assume the cause is there was no alterations to the code of the app in question. I can see why they would do this - Why test an app that just ran the same test and passed? However, my situation is different; testing the app is not my primary concern, but testing what the app controls.
My question: My test will be run on a continuous loop, and the app will not be altered or changed. So is there any way around this?
I assume the cause is there was no alterations to the code of the app
in question.
This is not true. You can run the same test thousands of times with Espresso without changing a line of code.
Make sure you're running it the correct way:
java -jar spoon-runner-1.1.0-jar-with-dependencies.jar \
--apk example-app.apk \
--test-apk example-tests.apk
Also keep in mind that the devices running the test should be visible in adb (run adb devices to check).
With Spoon, a test will not run twice if the first test passed. This is cause it believes if it runs the test again, it will pass and there is no reason for that. Bad design on Square's part if you ask me.
The solution is: gradle clean spoon. clean will regenerate the res files (among others) and make spoon believe that it is essentially a different test. This makes running tests take longer than it should. But it works.
I have a following problem with robotium. I have test package with few unittests for my app, this package also includes Robotium tests, the structure is simple as following:
\tests
\data
\datatests
\robotium
When I start test for only robotium package everything works fine, but when I start All tests in my test app robotium tests are failing as the wont initialize activity at all (not sure but no view is layouted, and I'm sure screen is active all the time), and log I get is only that View robotium was searching is not found.
I have no clue what causes it, so I would appreciate any help.
This can happen if there are unfinished activities from your tests. In all robotium tests your tearDown() method should call solo.finishOpenedActivities().
I have an app to be tested, called app A.
I also have a test project for automated testing of this app.
I want to have a second app which includes these test cases, so that I can run all test cases for app A by starting another, app B.
I don't want to start tests in Eclipse, I want to start them directly from the phone where the app should be tested
Someone knows a solution?
BR
I guess you want to run the tests from your code, in such case this post, presenting a solution to run instrumentation from code, will be of help.
Maybe i didnt' understand... You want to start an activity from MainActivity but the 2nd activity has to be hidden from launcher?