Calculon

1,966 views

Published on

Lightning talk I did on the Calculon testing DSL for Android on a Google developer day

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,966
On SlideShare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Calculon

  1. 1. Calculon A Java DSL for Android functional testing© 2010 Matthias Käppler www.qype.com
  2. 2. My fortune cookie says... Every half-way complex app should be backed by an automated test suite!
  3. 3. Tests should be... Easy to write.
  4. 4. Tests should be... Easy to read!
  5. 5. Sorry, I dont speak binary public void whatInHeavensNameDoesThisEvenTest() { final Button b = (Button) getActivity().findViewById(R.id.b); ActivityMonitor monitor = getInstrumentation().addMonitor( BarActivity.class.getCanonicalName(), null, false); getInstrumentation().runOnMainSync(new Runnable() { public void run() { b.performClick(); } }); getInstrumentation().waitForIdleSync(); assertTrue(getInstrumentation().checkMonitorHit(monitor, 1)); }
  6. 6. What a mess!
  7. 7. Calculon to the rescue!
  8. 8. Calculon to the rescue! assertThat(R.id.button).click().starts(BarActivity.class);
  9. 9. Calculon is... … a testing library for Android.
  10. 10. Calculon is... … deployed as a JAR.
  11. 11. Calculon is... … a DSL*. *as far as thats possible in Java.
  12. 12. Calculon is... … open source!
  13. 13. Testing with Calculon Tests with Calculon are written as functional Activity tests. ActivityInstrumentationTestCase2
  14. 14. Testing with Calculon public class FooTest extends FunctionalTest<FooActivity> { public FooTest() { super("com.example", FooActivity.class); } public void testStuff() { ... } }
  15. 15. Assertions public void testStuff() { // testing against activities assertThat()... assertThat(getActivity())... assertThat(someOtherActivity)... // testing against views assertThat(R.id.some_button)... assertThat(someButton)... // of course all Junit assertions work as well assertEquals(...) assertNotNull(...) ... }
  16. 16. Activity Assertions public void testStuff() { // testing for an orientation assertThat().inPortraitMode(); // testing for views assertThat().viewExists(R.id.some_button); // testing for input actions assertThat().keyDown(KeyEvent.KEYCODE_BACK)... // testing for custom predicates assertThat().satisfies(new Predicate<Activity>() { public boolean check(Activity target) { return target.isTaskRoot(); } }); }
  17. 17. View Assertions public void testStuff() { // testing for view state assertThat(R.id.button).isVisible(); assertThat(R.id.button).isGone(); // testing for input actions assertThat(R.id.button).keyDown(KeyEvent.KEYCODE_BACK)... assertThat(R.id.button).click()... assertThat(R.id.button).longClick()... // testing for custom predicates assertThat(R.id.button).satisfies(new Predicate<View>() { public boolean check(View target) { return target.getVisibility() == View.VISIBLE; } }); }
  18. 18. Action Assertions public void testStuff() { // testing for actions that launch a new activity assertThat(R.id.b1).click().starts(BarActivity.class); // testing for actions that finish an activity assertThat(R.id.b2).keyDown(KeyEvent.KEYCODE_Q).finishesActivity(); // testing for actions that change something assertThat(R.id.b3).click().implies(R.id.b2).isGone(); assertThat(R.id.b4).click().implies(getActivity()).inLandscapeMode(); assertThat(R.id.b5).click().implies(new Predicate<Model>() { public boolean check(Model target) { return target.someAttribute() == 5; } }); }
  19. 19. Thanks! $ git clonegit://github.com/kaeppler/calculon.git

×