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 { ... }
Good work. This is very useful post.Thanks for share it.
ReplyDeleteandroid application development
I tried to use version 2.0-alpha-2 and it crashed with:
ReplyDeletejava.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!