Approximate timeline for native Junit 4 + android-free unit testing support?

569 views
Skip to first unread message

Kaushik Gopal

unread,
Feb 25, 2014, 2:18:17 PM2/25/14
to adt...@googlegroups.com
I'm looking for two things specifically:
  • running tests from the IDE (Android Studio) without needing to go through the Android Stack (so pure POJO testing).
  • Junit 4 support

There have been quite a few threads on the subject and my intention is not to beleaguer the point. I'm just looking to see if
  1. is this on the roadmap at all
  2. if yes, an approximate timeframe (months or year)

Knowing this information will greatly help me form a testing strategy for my current projects (if i should look at external libraries/tools or bite the bullet until elegant/native support comes in).

Cheers and Rock on.


Xavier Ducrohet

unread,
Feb 25, 2014, 2:33:20 PM2/25/14
to adt...@googlegroups.com
We're working on JUnit4 support.

For pure POJO testing, make a pure Java project, you'll be able to run tests there.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Kaushik Gopal

unread,
Feb 25, 2014, 2:52:43 PM2/25/14
to adt...@googlegroups.com
Thanks Xavier :). 

Just to clarify my POJO testing point: 

I would like to run it from Android Studio itself, parallel to my existing Android project environment (since the POJOs i'm testing are part of my Android project). I can run AndroidTestCase, TestCase & ActivityInstrumentationTestCase2 flawlessly from AS and it's perfect for a quick workflow. Achieving something similar for POJO tests (without going through the Android stack, so it's lightening quick) would be awesome.

If this is already possible, please let me know if i'm missing something blatantly obvious.

Siva Velusamy

unread,
Feb 25, 2014, 3:01:27 PM2/25/14
to adt...@googlegroups.com
If you can structure your project so that the POJOs live in a separate
Java module, then this should already work. See this example:
https://android.googlesource.com/platform/tools/base/+/master/build-system/tests/multiproject/util/build.gradle
You can add Junit tests to the src/test/java folder, and the Gradle
Java plugin and Android Studio can run those.

If your classes are inside an Android module (app/library), then
you'll have to run them on the device.

Xavier Ducrohet

unread,
Feb 25, 2014, 3:01:46 PM2/25/14
to adt...@googlegroups.com
Having a separate project doesn't mean you cannot run it from Studio. It's just a different module.

Kaushik Gopal

unread,
Feb 25, 2014, 3:57:19 PM2/25/14
to adt...@googlegroups.com
Thanks Siva + Xavier. Definitely make sense now.

Boaz Yagodiner

unread,
Mar 22, 2014, 4:38:32 AM3/22/14
to adt...@googlegroups.com
Hi Xavier (and others),

I tried to work with 2 modules with Android Studio but it works only partially (or maybe I missed something and you can correct me).
One of the reasons is that a lot of code needs access to the activities and fragments and they are in the Android module. While I can do things to override it makes the code far from clean.

So I tried this way:
Suppose I have a MyActivity. I also created MyActivityImpl such that:
1. MyActivityImpl doesn't inherit from Activity but it gets a reference to MyActivity so that it can call the Activity methods. This way I can mock the myActivity reference and unit test.
2. Each method in MyActivity contains one line - It simply delegates to MyActivityImpl.

The only problem with this is that some of Activity methods are final so Mockito can't override them.


Can you help?
Can you deliver android.jar without final keywords?


Thanks,
Boaz Yagodiner

Matías Dumrauf

unread,
Mar 24, 2014, 9:16:17 AM3/24/14
to adt...@googlegroups.com

Boaz Yagodiner

unread,
Mar 24, 2014, 12:07:55 PM3/24/14
to adt...@googlegroups.com
Yes.
I tried Robolectric with Android Studio a few weeks ago but I didn't succeed to debug the tests :-(
Also, I find it clean to test my code as if it was a regular Java code.

Anyhow, I just solved my problem using PowerMock which allows to mock final methods.

Thanks,
Boaz

Przemek Jakubczyk

unread,
Mar 26, 2014, 4:52:06 AM3/26/14
to adt...@googlegroups.com

Cesar Salazar

unread,
Oct 13, 2014, 8:40:17 PM10/13/14
to adt...@googlegroups.com
Reopening the initial question again: Is there an estimated date for Native JUnit 4 support?

I'm asking because this is my scenario right now: I have an application with more than 200 tests written in JUnit4, with Robolectric. They were working great on Eclipse ADT, but now we need to move to Android Studio and Gradle,... and I haven't found a way to make everything work smoothly. (After a lot of research, and apply some hacks, most of the tests work, but some of them, which use Mockito's spy, just throw an NoSuchMethodError)...

I think that eventually I will have to re-write my tests, due to the lack of support of Robolectric. The question is: Should I re-write them now in JUnit 3, or should I wait for JUnit 4 support? How long should I wait?

Thanks!

César S.

Nico Küchler

unread,
Oct 14, 2014, 12:51:30 PM10/14/14
to adt...@googlegroups.com
Hi all,

For robolectric + Android Studio and debugging you should try following setups

I have also a question to the future of unit testing. Xavier is there something similar planed like the robolectric project?

Current we doing 2 different test strategies with robolectric. 
  1. Unit testing, which can be mostly done with pure junit, but we need the robolectric support often for android related stuff. 
  2. The other strategy is doing integration tests with robolectric. This approach give us very fast feedback if we did break some application behaviour. 
As next step we use for real device testing espresso. But this tests need more run time as the same robolectric tests.

Dan O'Neill

unread,
Feb 18, 2015, 12:06:32 PM2/18/15
to adt...@googlegroups.com
Does the Unit Testing support described here, http://tools.android.com/tech-docs/unit-testing-support, which uses JUnit4 in screenshots imply direct support for JUnit4?  The InstrumentationTestRunner doc still does not state support for JUnit4.  

Jose Alcérreca

unread,
Feb 18, 2015, 1:57:46 PM2/18/15
to adt...@googlegroups.com
JUnit4 is supported if you use the unit test support because it's just a POJO (or mocked dependencies). If you need instrumentation, the new AndroidJUnitRunner which is part of the Android Testing Support Library supports JUnit4.

Gautam Korlam

unread,
Feb 20, 2015, 2:12:35 PM2/20/15
to adt...@googlegroups.com
There is a gradle plugin to integrate Robolectric tests into Android Studio: https://github.com/kageiit/gradle-robojava-plugin

You may try that as well.
Reply all
Reply to author
Forward
0 new messages