Your SlideShare is downloading. ×
Calculon
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Calculon

1,500
views

Published on

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

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,500
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Calculon A Java DSL for Android functional testing© 2010 Matthias Käppler www.qype.com
  • 2. My fortune cookie says... Every half-way complex app should be backed by an automated test suite!
  • 3. Tests should be... Easy to write.
  • 4. Tests should be... Easy to read!
  • 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. What a mess!
  • 7. Calculon to the rescue!
  • 8. Calculon to the rescue! assertThat(R.id.button).click().starts(BarActivity.class);
  • 9. Calculon is... … a testing library for Android.
  • 10. Calculon is... … deployed as a JAR.
  • 11. Calculon is... … a DSL*. *as far as thats possible in Java.
  • 12. Calculon is... … open source!
  • 13. Testing with Calculon Tests with Calculon are written as functional Activity tests. ActivityInstrumentationTestCase2
  • 14. Testing with Calculon public class FooTest extends FunctionalTest<FooActivity> { public FooTest() { super("com.example", FooActivity.class); } public void testStuff() { ... } }
  • 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. 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. 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. 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. Thanks! $ git clonegit://github.com/kaeppler/calculon.git