Tuesday, February 26, 2013

Robolectric 2.0 alpha 2

I'm happy to announce the second alpha version of Robolectric 2!

As before, this release is alpha-quality, and targeted at early adopters. We expect that there'll be bugs. We expect APIs to change before final release. Please use this alpha only if you can deal with some churn.

Big thanks to Square and Pivotal for giving us time to work on this.


Changes since alpha 1:

  • Classes in the android support lib are now fully enabled without the use of shadows.
  • Resource loading is better than ever. Library project support is much more robust.
  • Internally we've switched from Javassist to ASM for the bytecode manipulation that works Robolectric's magic. This and a couple other optimizations give us a huge performance win: one project's test suite here at Square dropped from 163 seconds to 76.
  • We report our Build.VERSION.SDK_INT as 8 (Froyo) for now.
  • Should get along well with ActionBarSherlock.


Changes coming soon:

  • Removing even more shadows (most non-JNI Android classes should work without much shadowing) and enabling more of the SDK.
  • Easier TestRunner setup and configuration.
  • Performance and memory use improvements.
  • Ability to switch Android SDK level on a per-test basis.


Use it!

If you've been using Robolectric 1.x, see my blog post on migrating to Robolectric 2.0.

If you're new to Robolectric, just add this to your pom:
<dependency>
  <groupId>org.robolectric</groupId>
  <artifactId>robolectric</artifactId>
  <version>2.0-alpha-2</version>
</dependency>
Add a @RunWith to your test class and you're ready to go!
@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {
  ...
}

Caveats:

Currently only android.support.v4's Fragments and LruCache are supported. Support for the core android Fragments and LruCache from later SDK versions will be coming soon. As a workaround, you should be able to use the support versions for now.


Help:

If you find bugs, make an issue on our github project and label it with robolectric-2.

2 comments:

  1. Good work. This is very useful post.Thanks for share it.

    android application development

    ReplyDelete
  2. I tried to use version 2.0-alpha-2 and it crashed with:
    java.lang.NoSuchMethodError: org.objectweb.asm.commons.GeneratorAdapter.(ILorg/objectweb/asm/MethodVisitor;ILjava/lang/String;Ljava/lang/String;)V
    at org.robolectric.bytecode.AsmInstrumentingClassLoader$MyGenerator.(AsmInstrumentingClassLoader.java:246)

    When I use version 2.0-alpha-1 the test loads and starts to run but I crashes on the issue with ActionBarSherlock not dealing with Build.VERSION.SDK_INT=0.
    I tried to use "RobolectricTestRunner.setStaticValue(Build.VERSION.class, "SDK_INT", 15) ;" but RobolectricTestRunner.setStaticValue() isn't available.

    Any ideas?

    Thanks!

    ReplyDelete