Wednesday, May 15, 2013

Robolectric 2.0 final!


Robolectric 2.0 is, at long last, finished! Thanks for all the bug reports over the last week.

We'll have some blog posts in the coming week talking about new features.


Use it!

If you've been using Robolectric 1.x, see the 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</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.

Monday, May 13, 2013

Robolectric 2.0 RC2



Robolectric 2.0 is very nearly finalized! Thanks for all the bug reports over the last week.


Unless we find any showstopper bugs, I'll redeploy this as 2.0 final shortly.

Changes since alpha 3:

  • Bug fixes.
  • Performance improvements.

    Use it!

    If you've been using Robolectric 1.x, see the 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-rc2</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.

    Thursday, May 9, 2013

    Announcing the Robolectric 2.0 release (candidate)!

    We're very, very pleased to announce that Robolectric 2.0 is now feature complete and nearly ready to be minted (note the subtle lamb pun there)!

    Thank you to Square for giving us Day 4 of the Seven Days of Open Source campaign of free software awesomeness: Announcing Robolectric 2.0 RC.

    Robolectric has a new home!


    To give us more flexible management of access for community contributors, Robolectric is moving to its own GitHub org.

    From now on you'll find the main Robolectric GitHub project here: http://github.com/robolectric/robolectric

    You can update your git repos with this command:
    $ git remote set-url origin git://github.com/robolectric/robolectric.git

    Robolectric has a new home, but the folks behind it remain the same: big thanks to Pivotal Labs, Square, and other backers for time and support!

    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.

        Friday, April 5, 2013

        The Test Lifecycle in 2.0

        Starting with Robolectric 2.0 alpha 3, there are some changes in how Robolectric prepares to run your tests.

        Finding Your Application

        By default, Robolectric first looks in your AndroidManifest.xml for the class to load as your application:

        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.myapp">
          <application android:name=".Application"/>
        </manifest>

        That will cause a class called com.myapp.Application to be loaded. However, if you create a class with the same name and package, but with "Test" prepended to the class name, Robolectric will load that instead.

        package com.myapp;
        class TestApplication extends Application {
        }

        The Application Lifecycle

        Robolectric now automatically calls an application's onCreate() method before the test runs, and onTerminate() after the test runs. Note that this a change from earlier versions. If you want to prevent your application's onCreate() method from being called, you can override it in a test class and have it do nothing.

        If your test application implements the TestLifecycleApplication interface, it will get called with a few more useful events:

        class TestApplication extends Application
            implements TestLifecycleApplication {
          @Override public void beforeTest(Method method) {
          }

          @Override public void prepareTest(Object test) {
          }

          @Override public void afterTest(Method method) {
          }
        }

        The overall steps taken when running each test, then, are:
        1. Create your application.
        2. Call application.onCreate().
        3. Call application.beforeTest().
        4. Call application.prepareTest().
        5. Run the test.
        6. Call application.onTerminate().
        7. Call application.afterTest().

        These changes should make it possible for many people to avoid overriding RobolectricTestRunner altogether. Note that you can still change this by using your own subclass of RobolectricTestRunner, which provides a different TestLifecycle class.

        Tuesday, March 5, 2013

        Using ActionBarSherlock with Robolectric 2

        Hey everybody! You look great today!

        We're getting closer to seamless integration with ActionBarSherlock in Robolectric 2, but it's not quite there yet.

        To use the ActionBarSherlock library with our 2.0-alpha-2 release, you'll need to