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.
Related
I can't execute a simple test with cucumber for a project. I am on Intellij 13 Community, with cucumber plugin.
I wrote my feature file in my features directory, I have also implemented my steps creating them with the help of the plugin. My steps in the feature files are recognized by intellij, which can navigate and go to the step implementation.
When I try to run my scenario, if fails stating "Undefined step". Any help will be greatly appreciated.
Here is how i organized my project :
It sounds as if you are trying to run the feature from Idea. It also sounds as if you have some issue with the wiring of your project.
My approach would be to start with something that works and then modify it to suit your needs. A project that works is the Java skeleton provided by the Cucymber team. Download or clone it from GitHub: https://github.com/cucumber/cucumber-java-skeleton
You should be able to build this project using Maven, Ant, or Gradle. It will also be possible to open it using IntelliJ IDEA and modify it to suit your needs.
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?
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 think i do not understand Android Library Project correctly. I'm having the following issue:
i have a library project in a package a.b.c.lib
i have a application which is uses the library project in package a.b.c
i have another application which is uses the library project in package a.b.c.pro
Everything is OK with the application in package a.b.c, however i hit the following issue (during runtime) in the a.b.c.pro app:
java.lang.NoClassDefFoundError: a.b.c.lib.c1$c2
the same class is found OK in the a.b.c app.
So, what is the right way to define packages in this case?
There's no right way. Every way is right. It should work so I think the problem is not in packages. Do you use Proguard for obfuscation? It can remove some classes which are used in your app. Also such errors happen because of some bugs in the toolchain. Try to clean and rebuild you app .
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.