Android Junit Test Cases - android

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.

Related

Android Studio Tests are successful but do not stop junit

I am new to Android and building an app in Android Studio. I have written some tests using JUnit and Mockito.
The tests run successfully and in the run console the text Process finished with exit code 0 is shown.
However, the thread seems to remain active, the stop button is enabled and nothing happens even if I click on it. If I try to start multiple test configurations, they all remain active although the processes finish successfully.
I hope the question is clear enough... I have searched a lot for the answer and mananged to find nothing.
That can be fixed by following these steps:
Open 'Run' tab in Android Studio
Tap 'X' next to test which has just passed
Ok, so after a little more research and some more checking I have concluded that the problem stands in a visual bug of Android Studio. Apparently the tests do indeed stop, the thread running them too. The problem is purely visual.

Android Studio: testing is slow

Every time I want to do a quick test of some code, android studio takes 20-40 minutes loading an emulator which then either crashes my laptop or makes it run very slow. Is there any way to just use the system log without loading the whole app, similar to the System.out.Prinln() feature in net beans?
I understand that the question is about running your app for quick testing and not about automated tests. But you can learn a lot by trying to adapt writing tests, and they can help you to solve your problem.
1) For code without android dependencies you can write JUnit tests and run those just on JVM to test the code. Bonus: you'll start with creating your testsuite!
2) For code with android dependencies: a) Try to be better in separating platform specific code and internal logic so you will be able to cover more code with unit tests. b) You can use roboelectric and test everything without emulator/device for the rest.

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.

Spoon & Espresso - Build Successful. Thats it?

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.

Robotium test won't start after unit tests are run

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

Categories

Resources