Robotium test won't start after unit tests are run - android

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().

Related

How do you write an Androidx Instrumentation that runs multiple Instrumentations?

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?

Breakpoint in Manager class not being hit in Junit test - Android Studio

So I am running a few tests in AndroidJunit, which tests a manager class that I created for my application. When I add breakpoints to the Test class and go into debug mode, they get hit just fine. But if I add break points to the Manager class that I am testing in junit, they do not get hit when I run the tests. Is it possible to hit break points in a non-test class when running junit in Android Studio? I'd appreciate any suggestions on how to solve this issue. Logs also do not show up when I place them outside of the Test class.
EDIT/UPDATE
So I have been able to dig a little deeper and found out that the problem here was using Mockito with my Tests. So if I replace InstrumentationRegistry.getContext() with context = Mockito.mock(Context.class); then the debugger no longer hits the breakpoints placed in the manager. However, I need to use Mockito with my tests, so I'm in a bit of a predicament. Does anyone if there is a manner that I can use Mockito in that allows me to set and reach break points in a non-test class? Thank you.
FYI, I am passing context into the manager class method like this
manager.checkSharedPreferences(context), and the manager is extracting values from shared preferences.

Execute Code after all Android Instrumentation tests have finished

I have a large set of Android Instrumentation (Espresso, Robotium, UI Automator) test cases spread over many different test classes.
After every test case in every test class has finished, I want to execute some piece of code.
Has anybody every tried this? Tipps are greatly appreciated!

Robotic tests should be independent

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.

Android Junit Test Cases

How can I stop the android Junit test application in the mid.I want to stop the execution of my application in particular place.Is it possible?Please give your suggestion..
Set the breakpoint in desired place in IDE and run test project in debug mode.
Note that debug execution is a bit slower than run mode.
hope this answer satisfies your question
click on the stop button in the junit column. But again if you return, the testcases will be running from the beginning.

Categories

Resources