Android Studio JUnit pure Java tests - java

Usually, when developing algorithms for android applications in eclipse, I used pure Java projects that would have a dependency set to the android project and could then run JUnit tests in the pure Java classes. This had great advantages since I could run my tests on my algorithms and logic classes really quickly without any deploying.
Could anyone tell me if it is possible (and how) to do something similar with android studio??
Thanks!

How about the gradle android test plugin?
("A Gradle plugin which enables good 'ol fashioned unit tests for Android builds." sounds like what you want)
Or maybe something like robotium / roboelectric.

Related

Selenium for IntelliJ IDEA

I am relatively new to Selenium.
Currently in my company we use Eclipse to create and run our testing automation (Maven/Cucumber/Selenium).
We also use IntelliJ IDEA for Java development.
My question would be if it is possible to use IntelliJ IDEA for testing automation similarly like we use Eclipse (Maven/Cucumber/Selenium)? I mean to build test automation scripts.
If yes, so you could you kindly recommend any tutorial where it is explained how build those projects for IntelliJ IDEA.
Thank you in advance
this question has a simple answer. Whatever your company does in Eclipse, you can do in InteliJ.
BOTH Eclipse and InteliJ are IDE's (An integrated development environment for building applications that combines common developer tools into a single graphical user interface). So basically, consider them both like "code editors". There is really no difference in using Eclipse or InteliJ (maybe some UI differences).
Personally, I prefer InteliJ based on cleaner UI. You pick yours.
Here is one useful tutorial. Good luck :)
https://www.youtube.com/watch?v=JPLk4Z0U0yQ

Unit testing framework for my own android library

I'm building an android library for Android developers.
I want start unit testing my library and I'm looking for a good framework.
I saw many articles about Robolectric, but the problem is my library doesn't contain a lot of UI/Activities/Services or other Android elements.
I want to use Robolectric for regular java unit testing, and in not many cases where I need Robolectric for UI/Services test I'll use the Robolectic features.
My questions are:
1. Can I use Robolectric for pure java unit testing? And if I can, I will be happy to get a good tutorial for this.
2. Does Robolectric is the best framework for my needs?
The short answer is yes.
You can setup your project with robolectric & Junit4. Then, when you have tests that do not touch any Android-specific bits, you can just run them as normal JUnit tests. When you need Robolectric, you use the Robolectric test runner. The runner you use is what makes the difference.
You run them all as JUnit tests anyway, so your entire library tests out with one run.

Automated testing tool for java post development

I have an existing java application which is developed in Netbeans this is my first major development project so i didn't think about the use of log4j & junit in first place(A good lesson learnt). since now i am at the end of the project i miss these two . is there is any tool or jar which can create automated testing & logging with minimum effort ? I guess Adding log4j is easy but what about junit ?
There is nothing to say that you cannot use Junit after you have created a project. It means that you are not making use of test driven development, but there is no reason why that is an issue once you have already created your project.
I would recommend the netbeans tutorial on exactly how to do that:
https://netbeans.org/kb/docs/java/junit-intro.html

Regular JUnit in an Android project

I've been trying to figure out how to include standard JUnit 3.x (or even JUnit4.x) tests in my Android applications. I want to use JUnit over the Android unit test tools because it is faster and runs directly in my IDE (where the Android JUnit tools need to be deployed to the device or emulator 1st). I also want to use JUnit to impose proper SoC (Separation of Concerns). Originally I had set up multiple modules to allow for this, the Main Android module and a core library module where the main module would have all of the Android specifics and the core module would have Plain Old Java Objects (POJOs) and JUnit goodness.
Recently I started working on an Android project where I developed a library to handle some low level android specific work and expose it as high level operations to the main module. The problem is that I need to use JUnit in the library module but I don't want to break out yet another module to do so. In an ideal world I would have:
Main module: includes all the high level UI and controller logic to navigate between activities, fragments, etc. Depends on MyLib.
MyLib: Contains high level interfaces wrapping low level logic to handle things such as android specific networking, persistence, accelerometer reads, etc. Lots of POJOs involved in some of the low level logic. Also includes an example or demo app to exercise these interfaces directly. Includes the ability to run JUnit on the POJOs.
Am I living a pipe dream or is there a way to intelligently set this up using current development tools? I use IntelliJ Idea primarily but would be open to an Eclipse specific solution as well.
The problem you will run into with running your tests directly in the JUnit test runner is that you will not be able to call any com.android.* classes. That is because these classes, in android.jar, are stubbed out in your SDK. Only the Dalvik- byte code versions of these have actual implementations those only run in the emulator.
Avoiding calls into com.android.* classes is very difficult, especially given that so many Android methods require a Context.
I too find this a bit frustrating because the emulator is slow to launch and slow to execute code. It makes test development very tedious.
The only luck I have had using the JUnit test runner w/out the emulator is to create a separate, non-Android project that points at my project files. This allowed my to launch JUnits outside of the emulator, however I was very limited in what classes I could actually test.
In short
Use Junit for testing classes and static methods.
Use Instrumentation to test the click-ux response of your app
Instrumentation is a pain to get started, takes time to learn. So invest time in hello worlds a lot. Its a whole new world.

Using different build path for Unit Testing In Eclipse

I'm doing Java development in eclipse and using JUnit. My application uses an old version of a library because of platform restrictions. Is there any way I can run my unit tests with a new version of the library? How do you configure a different build path for unit testing?
To clarify for everyone below:
Here is the problem. Our platform requires a really old version of the java Servlet library. But we want to use ServletUnit (a library for testing servlets in a unit testing framework). This library will only work with newer versions for the java servlet lib. I don't care that we test with a different version of the servlet library, it outweighs the negative.
You can do this by having your unit tests in a different project, so the projects will have different build paths.
The better question is WHY you want to do this. It's a bad idea to run your tests against something other than the production code. Why not either update the library in the application, or use the old library for the tests?
In response to your edit:
If you don't care about testing with the same libraries you use in production, then you don't care about code quality or correctness. There's no point in answering this because no answer will be a good fix to your problem. Your time would be better spent upgrading your platform to use the newest version of servlets.

Categories

Resources