I am new to Android. I tried googling for a solution for how to do Unit testing for Android in IntelliJ and found http://confluence.jetbrains.com/display/IntelliJIDEA/Creating+Unit+Tests. What I am trying to achieve is I have begun to write a simple Twitter Client and would like to write some unit tests for it Initially when trying just to write a test class within src I got "Java.lang.RuntimeException - Stub!", and understand from looking at another SO post that this is because you cannot run a Unit test within the Android application itself (i.e. you need to create a test module).
However, when I open IntelliJ 13 I can't see the option to create a test module. All I see if I go to New Project - Android is:
Gradle: Android Module,
Application Module,
Empty Module,
Library Module
with no option to create a test module. Am I best off just choosing Empty Module and trying to create a test module from there?
Related
I have a library I'm creating using Intellij. I am doing TDD with ScalaTest and SBT to run my testing library. I want to set a breakpoint in Intellij for when it runs my tests to stop at a particular line so I can do inspection. How do I setup the run configuration to do this? When I extend my library class to extend App to give it a main method it doesn't even allow me to add it as the 'Application' run configuration in Intellij. I don't actually want to have that as a run configuration, I just want to be able to set breakpoints.
IntelliJ has a module to test scalaTest classes. Just right-click on the name of your class, and click on Debug in ScalaTest (the first time around, you should have a dropdown on Debug to select how you want to run it).
I'm trying to do some JUnit testing in IntelliJ IDEA. When I have a pure Java project the testing works fine. However I have a Android project I want to test on. The project contains both pure Java files and Android files. This error comes from trying to test a non Android class in a Android project. The non-android class is in the same test package as the Android test classes.
When I have my dependencies structured like this:
I get the following error:
I looked at another thread here on Stackoverflow and that said to put JUnit above the Android API in the dependencies list. When I try that I only get:
Class not found: "com.edit.mouseophonic.app.tests.TestClass"
Process finished with exit code 1
I have no idea how to solve this.
All help appreciated!
You have two options:
Use additional module for andoidTests which you can create in intellij idea http://www.jetbrains.com/idea/webhelp/testing-android-applications.html
Another option using maven-android-plugin https://code.google.com/p/maven-android-plugin/ and use appropriate dependencies. I prefer second.
I'm working on an Android Library Project utility class (no activity). I tried to test by configuring an other project but I can't make it work, I don't how to use instrumentTest and can't understand for what purpose I should use it (unit test or Activity using my lib).
i think this tutorial will help you : http://cyrilmottier.com/2013/06/27/a-productive-android-development-environment/ !
I am having big problemes with the uiautomator from google. I have a S3 not rooted and I can't run my tests on the device.
Error:
INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=com.test1.test
INSTRUMENTATION_CODE: 0
I saw some answers that pointed me to root the phone. I do not want to do that.
Please give me some answers how to use the tests.
I was having this same issue! I'm not 100% sure why it was happening, but I think it has to do with the way ant builds the JAR file. When I first started writing my uiautomation tests, I put them in the same project as some JUnit tests, which were in separate packages (one for the source classes and one for the tests). I created my uiautomation tests in the test package, and when I went to build and run them, I got an error that my test classes weren't being found.
I believe this was because the JAR file only included the source package and not the test package. So, I made a new project and put my uiautomation tests in a single source package, built the project, and pushed the JAR to my device. They ran smoothly after that!
I'm pretty new to this stuff too, so I'm not entirely sure if that answers your question. An alternative solution might be to move the UIA tests to the source package instead of creating a whole new project.
Also, Google's resources are really good for getting a basic feel for setting up and using uiautomation (if you haven't checked them out already). If you really can't find a fix, I'd recommend copying and pasting their demo into a fresh project and trying to get that to run: http://developer.android.com/tools/testing/testing_ui.html
I am creating a library for Android that others can include in their own project. So far I have been working on it as a normal Java project with JDK 1.6 setup as system library. This works just fine in Eclipse when I add the android.jar.
The issue comes when I try to my build script. I am running Gradle and doing a normal compile and test build cycle. My thoughts were that it does not matter if I compile it with a normal JDK, since this is not a standalone application. The benefits by creating a normal Java project is that Gradle does support this much better. My project also does not contain any UI at all. However, the problem is that of course android.jar and the JDK contains lots of the same classes and I think that this is what messes up my build script. Everything crashes when running the tests (the tests are in the same project under src/test/java).
My question is, how should I create this project that is meant to be included in Android projects as a third party library? Should I create it as an Android project in Eclipse even though I am only creating a library that does not use any of the UI features? Also, should the tests be in a separate project?
Thanks for all responses!
Have you looked at the Android plugin for Gradle? It incorporates the ProGuard tool to package only necessary classes into your Android APK file, so might address your scenario. Have a look here: https://github.com/jvoegele/gradle-android-plugin/wiki
I will start with the simple question, the one regarding the test project. My experience is that is is better to have a separate test project. I have done this with success in many Java ME project, where the problems are similar. The test project only need to import the source code, not the libraries. Then there should be no problems with duplicate classes.
The other question is a little more difficult. My intuition tells me that the core project should be an Android project.