Custom Test Orchestrator or callback for start/finish - android

I'm using the Android Test Orchestrator to run my UI tests and i need to generate a report of the results when all the tests are finished.
I need to have a callback for when the orchestrator starts running the tests and when it finishes running all of them in a way that i can generate and save my report.
Given that a new instance of the AndroidJUnitRunner is created for every tests, i can't take advantage of onStart() and finish() to do that.
I was looking for a way to maybe provide a custom orchestrator so i can use the internal methods..

Related

How to run tests in android

I am using Robotium Solo to test the app
since I'm fairly new to app test, and Robotium
I have 3 methods in my test case - however, I want to run those tests, under certain conditions
otherwise they fail
I can do that if i write the entire test in one method, but i don't want to run it in one method, I
want to separate it into 3 methods
how do I make sure that the tests run only if I called the test methods, and not one after the other
In Robotium Test Application, every public method starting with keyword 'test' will be considered as one test case.
So, you can try using 2-3 methods with names starting by keyword test.( e.g. testA(), testB() etc.)
So, even if testA() fails, automation testing will continue to run for testB().
And results will be shown to the JUnit viwe.
Note:- the test cases are executed in the alphabetical order as per their names.
Hope this helps , ask if you are stuck somewhere.

Robotium: How to continue running test cases without restarting the app after each test?

In my test class, i have multiple test cases written. Now when I run the test project, after each test case the app is getting stopped and started again. In teardown I am calling solo.finishOpenedActivities().
I want to run all test cases without closing the activities.
I tried to remove solo.finishOpenedActivities from the tearDown method. In that case the next testCases are not getting executed and the test hangs after the first one.
So what is the proper way to have multiple test cases and not close the activities and continue running all the tests?
If the functionalities between your test cases are dependent on each other, then instead of writing them in separate testcases, write different functions related to different functionality and call then in same testcase according to their order of execution.
Because, after completion of each testcase, robotium will definitely close the activity and start a new activity for the other testcase.

Parameterized instrumentation tests on Android

I'm trying to write a batched instrumentation test (using ActivityInstrumentationTestCase2) for a particular Activity where I change the intent each time the test runs. I can do this with a single test, and just loop through stopping and restarting the Activity with the new intent, but this is not what I want. One reason is they really should be separate test runs. The other reason is, I'm using Spoon to generate a report when the tests finish, and the report will rightly think I only ran one test.
What I would like is it to treat a single test as a possibly infinite number of tests, and pass the data into the test each time the test runs.
Unfortunately you can't use Theories because it results in a RuntimeException where the InstrumentationTestRunner can't find my tests. Anyone have any luck with this?
You could always just create a "testing" intent. In order to simulate the relaunching of the application, make a method or several methods that reset all your static variables between tests. Then you can test the classes from within a testing intent inside the application itself using
assert("value", MyClass.myMethod);
resetStatics();
assert(true, MyClass,myMethod);
resetStatics();
I don't know how much this will help you, if at all, but this is how I started writing my own tests.
I recently discovered that you can add a public static Test suite() method to a test class, and when you run just this single test class, InstrumentationTestRunner will run the Test returned by this method. This is helpful because suite() can explicitly call any constructor of your TestCase, including one with parameters.

Android - JUnit test quits app after each test?

So I am trying to write automation test using Robotium for Android
I have a test suite related to my LoginPage, the problem is that setUp and tearDown get called beforfe and after every test, so it closes and opens the app on every single test case.
Is it possible to somehow avoid this, so that setup and tear down get called once for every test suit?
EDIT:
I am using ActivityInstrumentationTestCase2
Use SingleLaunchActivityTestCase instead.
I'm not sure about Robotium, but junit has #BeforeClass and #AfterClass annotations you can apply to a method such that it gets called only once before or after instantiation of the test suite. See more info here:
http://junit.sourceforge.net/doc/faq/faq.htm#organize_3

Testing Android activity with async tasks

How do you create unit tests for an Android activity that starts async tasks in onCreate? I would like to test the result of these tasks.
It is hard to write tests for a lot of Android functionality, since you can't instantiate classes like Activity outside of Android.
You might be better off doing a true unit test...test the function whose behavior you care about in isolation. Don't try to test it in the context of async task, activity, etc.
You might need to refactor your code a little bit to be able to do that, but its worth it to have testable code!
Running true units tests as mentioned in Cheryl's answer would be ideal. However if you still find yourself wanting to test the result AsyncTasks or any long running asynchronous operation in an Activity Test, Espresso is the silver bullet.
Espresso automatically waits for AyscTasks to complete and the developer can manually tell Espresso to wait for custom background tasks running via the IdlingResource APIs.
Here's a tutorial to help you get started: http://blog.sqisland.com/2015/04/espresso-custom-idling-resource.html
IdlingResource documentation: http://developer.android.com/reference/android/support/test/espresso/IdlingResource.html

Categories

Resources