SlideShare a Scribd company logo
1 of 19
Download to read offline
Calculon
     A Java DSL for Android functional testing




© 2010 Matthias Käppler
    www.qype.com
My fortune cookie says...



 Every half-way complex app should be
  backed by an automated test suite!
Tests should be...




           Easy to write.
Tests should be...




      Easy to read!
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));
 }
What a mess!
Calculon to the rescue!
Calculon to the rescue!




 assertThat(R.id.button).click().starts(BarActivity.class);
Calculon is...




    … a testing library for Android.
Calculon is...




        … deployed as a JAR.
Calculon is...




                 … a DSL*.

         *as far as that's possible in Java.
Calculon is...




           … open source!
Testing with Calculon



   Tests with Calculon are written as
         functional Activity tests.
   ActivityInstrumentationTestCase2
Testing with Calculon

  public class FooTest extends FunctionalTest<FooActivity> {


      public FooTest() {
          super("com.example", FooActivity.class);
      }


      public void testStuff() {
          ...
      }
  }
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(...)
     ...
 }
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();
          }
      });
  }
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;
          }
      });
  }
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;
         }
     });
 }
Thanks!



          $ git clone
git://github.com/kaeppler/calculon.git

More Related Content

What's hot

Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaRobot Media
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
 
Rx java testing patterns
Rx java testing patternsRx java testing patterns
Rx java testing patterns彥彬 洪
 
TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?Rob Myers
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test frameworkAbner Chih Yi Huang
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special CasesCiklum Ukraine
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJohn Ferguson Smart Limited
 
Bad test, good test
Bad test, good testBad test, good test
Bad test, good testSeb Rose
 
Unit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleUnit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleBenjamin Eberlei
 
Unittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleUnittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleBenjamin Eberlei
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기NAVER SHOPPING
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Kirill Rozov
 
How do we use hooks
How do we use hooksHow do we use hooks
How do we use hooksJim Liu
 
100% Code Coverage - TDD mit Java EE
100% Code Coverage - TDD mit Java EE100% Code Coverage - TDD mit Java EE
100% Code Coverage - TDD mit Java EEStefan Macke
 

What's hot (18)

Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon Galicia
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
Rx java testing patterns
Rx java testing patternsRx java testing patterns
Rx java testing patterns
 
TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?TDD? Sure, but What About My Legacy Code?
TDD? Sure, but What About My Legacy Code?
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
 
Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit Tests
 
Agile mobile
Agile mobileAgile mobile
Agile mobile
 
Bad test, good test
Bad test, good testBad test, good test
Bad test, good test
 
Unit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleUnit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by Example
 
Unittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleUnittesting Bad-Practices by Example
Unittesting Bad-Practices by Example
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1
 
How do we use hooks
How do we use hooksHow do we use hooks
How do we use hooks
 
Introduzione al TDD
Introduzione al TDDIntroduzione al TDD
Introduzione al TDD
 
Junit With Eclipse
Junit With EclipseJunit With Eclipse
Junit With Eclipse
 
100% Code Coverage - TDD mit Java EE
100% Code Coverage - TDD mit Java EE100% Code Coverage - TDD mit Java EE
100% Code Coverage - TDD mit Java EE
 

Viewers also liked

The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...Brian Solis
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 

Viewers also liked (8)

Secure Webservices
Secure WebservicesSecure Webservices
Secure Webservices
 
Testing With Open Source
Testing With Open SourceTesting With Open Source
Testing With Open Source
 
Hands on the Gradle
Hands on the GradleHands on the Gradle
Hands on the Gradle
 
Crear o Morir, Resumen del libro
Crear o Morir, Resumen del libroCrear o Morir, Resumen del libro
Crear o Morir, Resumen del libro
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Similar to Calculon

Android testing
Android testingAndroid testing
Android testingSean Tsai
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testingjeresig
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intentadmin220812
 
Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4jeresig
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdffashionfolionr
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo Ali Parmaksiz
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testingVisual Engineering
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42Yevhen Bobrov
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creatorsGeorge Bukhanov
 
How to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happyHow to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happyIordanis (Jordan) Giannakakis
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonbeITconference
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfcalderoncasto9163
 

Similar to Calculon (20)

Android testing
Android testingAndroid testing
Android testing
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intent
 
Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creators
 
Google guava
Google guavaGoogle guava
Google guava
 
How to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happyHow to build rock solid apps & keep 100m+ users happy
How to build rock solid apps & keep 100m+ users happy
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Easy Button
Easy ButtonEasy Button
Easy Button
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 

Calculon

  • 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 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)); }
  • 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 that's 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 clone git://github.com/kaeppler/calculon.git