Wednesday, May 8, 2013

Robolectric 2.0 alpha 3


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

We're now feature-complete on Robolectric 2.0! As before, this release is alpha-quality, and targeted at early adopters. We expect that there'll be bugs. APIs may change somewhat 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 2:

  • Massive realism upgrade: we removed many, many shadows, particularly for views and widgets, so they'll behave much more realistically.
  • Dramatically improved resource loading, with support for themes and styles.
  • Easier TestRunner setup and configuration.
  • The new @Config annotation to specify config for a test class or test method:
    • The SDK level to report: @Config(reportSdk=Build.VERSION_CODES.FROYO)
    • Qualifiers for resource loading: @Config(qualifiers="fr-port-hdpi")
    • Custom shadow classes to enable.
  • For classes and methods that aren't explicitly shadowed, Robolectric now calls through to the real SDK code.
  • Views now complain if you try to pass in a null Context. Don't do it!
  • SDK method execution is now much much faster, especially in cases where we use the actual SDK code rather than a shadow (which will increasingly be the normal case).
  • Performance and memory use improvements.

    Changes coming soon:

    • Ability to switch Android SDK level on a per-test basis. The @Config annotation will allow you to specify which version of the SDK to emulate: @Config(emulateSdk=Build.VERSION_CODES.FROYO)
    • Performance and memory use improvements.

      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-3</version>
      </dependency>
      Add a @RunWith to your test class and you're ready to go!
      @RunWith(RobolectricTestRunner.class)
      public class MyActivityTest {
        ...
      }

      Help:

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

      1 comment:

      1. Hi, can you provide up to date samples for android? The sample project on GitHub is for the old version of robolectric. And the samples on the web you're refferring to seems to be outdated aswell.

        ReplyDelete