Calculon
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Calculon

on

  • 1,923 views

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

Statistics

Views

Total Views
1,923
Views on SlideShare
1,913
Embed Views
10

Actions

Likes
0
Downloads
18
Comments
0

3 Embeds 10

http://www.linkedin.com 6
https://www.linkedin.com 3
http://coderwall.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Calculon Presentation 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