Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Calculon - A Java DSL for Android functional te...

Calculon - A Java DSL for Android functional testing

Matthias Käppler

October 21, 2012
Tweet

More Decks by Matthias Käppler

Other Decks in Programming

Transcript

  1. Sorry, I don't 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)); }
  2. Testing with Calculon Tests with Calculon are written as functional

    Activity tests. ActivityInstrumentationTestCase2
  3. Testing with Calculon public class FooTest extends FunctionalTest<FooActivity> { public

    FooTest() { super("com.example", FooActivity.class); } public void testStuff() { ... } }
  4. 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(...) ... }
  5. 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(); } }); }
  6. 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; } }); }
  7. 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; } }); }