Oct 24 2011

Book Review: Android Application Testing Guide (Deigo Torres Milano) by PACKT Publishing

Category: Android,Book Review,Books,Programming,Toolittichai @ 10:39 am

Android Application Testing Guide book  (Diego Torres Milano) by Packt PublishingWhen I was offered to review this book, I was so excited. The topic is probably one of the least popular topics in the Android development circle based on the number of books written on Android. Most of the books in the market tend to cover solely on the area of actual development because it gives readers an instant gratification when creating something. However, it is unfortunate (but true) that the application testing might be something most developers least think about, or if they do, they not do it systematically. (I’m guilty of this as well.) I would like to expand my horizon by learning from the pros. That’s why I’m so excited for a chance to review this book.

The “Android Application Testing Guide” is a very practical book introducing available frameworks and most widely used tools & techniques to improve the qualify of the application by engaging in the quality control and testing throughout the development cycle (not just start testing at the end). This agile development concept called the Test Driven Development (TDD) relies on repeatable short cycle to trying to catch and take care of potential issues (i.e., bugs) as early as possible.

The first chapter explains what involves in the different stages of testing in the Android development including unit test, integration test, functional or acceptance test, system test, and performance test. It starts introducing the Android testing framework extending JUnit which provides the complete testing framework suitable for the end-to-end testing strategies.

The chapter 2 starts working on the actual testing using JUnit which is the default framework for Android testing project and is supported by Eclipse which it the most widely-used IDE for Android development. The chapter jumps right into the step-by-step on how to create the Android test project which is a separate from its development project being tested. The test project will have independent structure and a set of its own components. Having a separate project is the best practice because from the production build’s standpoint, testing codes will not be included in the actual build, thus it will be not be in the APK.

Chapter 3 dives into individual building block in the Android SDK tool.  This covers Assertions, TouchUtils class (to simulate the touch events), Mock objects (to simulate mock objects in order to isolate the tests), TestCase class, and Instrumentation. There is an extensive explanation of individual component accompanying by code samples.

Chapter 4 talks about the concept of Test Driven Development. Again, it is the strategy of performing tests along the development process – not at the end as in the traditional approach. This even includes writing test cases (and test codes) first right after studying the requirements, and then writing the actual codes to satisfy (having the “pass” results) the test cases. Author claims that this approach of creating test cases this early will ensure that tests will be performed instead of, if left until the end, it is highly possible that they would have been forgotten or ignored. I agree with the concept. But in reality this may not work with all types of the projects, and this is confirmed by author in a few paragraphs later to use your judgement and expertise in applying this approach to wherever suitable. The latter part of the chapter shows samples on how to apply the TDD in the step-by-step sample application and tests, which I found this makes the case very compelling.

Chapter 5 introduces the Android Virtual Device (AVD) which is the next best thing to the real devices. The obvious advantage of using AVD is ability to create different Android configurations to run tests. The Headless Emulator (no window displayed) is also mentioned here allowing the automated tests via command line with no windows. I really enjoy many samples of what you can do with command-lines especially when you can simulate different device’s conditions including network bandwidth throttling, or different locales, etc. Later in the chapter, it talks about the support of the Monkey application (you can read more about Monkey Theorem here) which allows random event generation. It also demos the server-client setup and test scripting with Monkneyrunner.

Chapter 6 talks about the Behavior Driven Development which, according to author, is considered the evolution of the Test Driven Development and a need of Acceptance Testing. In summary, the approach emphasizes not only to include the business or end users in testing, but also to use non-technical terms in the test cases that business or end users would understand. Personally I think the concept is too abstract than practical. However, the introduction of Fitnesse and Slim tools makes the point to see its usefulness especially the part of “Wiki”-style test cases and test result documentation.

Chapter 7 contains all practical real-world samples of the disciplines and techniques you can use in the different situations. This includes testings on activities and applications, databases and Content Providers, UIs, exceptions, parsers and memory leaks. Couple tools are introduced here including EasyMock which provides mock objects for interfaces, and Hamcrest which is a library of matcher objects for comparison.

Chapter 8 continues the introduction of Agile technique with Continuous integration. Similar to continuous testing, it is suggested that integration should be done frequently early in the process and in small steps. The most common practice, as stated by author, is to trigger the build process after every commit to the source code repository. The chapter goes in details how to setup the automate building process using ant, the version control repository using Git, the continuous integration with Hudson, and test result analysis using nbandroid-utils.

Chapter 9 discusses one of the most critical components in designing Android application which is performance. As we all know, with a device which has limited computing power and battery life, balancing between performance and effective use of resources is something developers should keep in mind when designing an Android application. The chapter again introduces us with a series of tools and techniques for performance testing. This includes using traditional LogCatlogging, extending Instrumentation, Traceview, dmtracedump, and Caliper microbenchmarks.

Chapter 10 – alternative testing tactic is not for the most Android developers as it involves building Android from source code. Again, more tools are introduced. Even though it is very technical, it is still a good read.

Summary:

I have to say that for a novice Android developer like I am, I learn a lot from reading the Android Application Testing Guide. Best-in-class testing techniques are covered in this book which are commonly practiced in the agile development. These include Test Driven Development, Behavior Driven Development, Continuous Integration, etc. They in generally oppose to the traditional approach of doing test and integration at the end of development cycle. However, as author states in the book, there is no silver bullets in software development – the suggested testing approaches might not apply to certain needs or projects. But I can see that for a large complex project, applying these methodologies and techniques will likely increase in the productivity and quality.

Numerous tools are introduced in this book. This may be one of the big issues for those who are less-advanced in Android development. Since there is no common repository of these tools, extended knowledge of a varieties of open-source tools, and ability to incorporate them with the development process are required. I wish that there would be consolidated repository for all testing tools or even better all required testing functionality would be built-in in the SDK. Well, before when that would happen, this Android Application Testing Guide book is probably one of a few reference books that has the complete collection of Android testing topics.

Disclosure: I received the Android Application Testing Guide e-book from Pubkt publishing with no charge. I’m not compensated for this book review. The content expressed in this post is personal opinion.

 

Tags: , , , , , , , ,


May 30 2011

Book Review: Learning Android by Marko Gargenta (O’Reilly Book)

Category: Androidittichai @ 4:24 pm

Learning Android by Marko Gargenta by O’RelilyLearning Android is a collection of many years’ experience of the author, Marko Gargenta, who has been teaching the Android bootcamp training to thousands of software developers. It covers all necessary topics about Android starting from a high-level overview (history and concept) until the nuts and bolts (writing codes for Twitter-like application called Yamba application).

As an avid user of both Android phone and tablet myself, I have an interest in learning about this platform and hopefully writing some applications on it. I’ve read many Android books before. Most cover a lot of topics but without coherence – you feel like you learn a lot about many things but you still can’t put them together to make them work well. This book is one of the few books I really like. It walks you through creating a reasonably complex application from scratch. Not only the author explains the concepts and sample codes really well, but he also guides you through his thinking and design process on how to write a good application. The latter, I think, is more important for laying a good foundation for writing other applications in the future. The tips, suggestions, and notes throughout the book show you that Marko really understands what works and what does not.

I highly recommend this book to everyone who has an interest in learning about programming on Android and would like to build a good foundation on good programming practices. People who know Java programming language should have no problem following the sample codes presented in the book. But for those who don’t, I suggest getting yourself familiar with Java first. (Obviously if you don’t plan to use any other mobile cross-platform or rapid development tools, you must write in Java codes.) Knowing it a bit will help you tremendously with understanding the sample codes. Needless to say, you can still pretty much read for concepts, tips, and even some codes because the explanation from the author is very precise and clear.

It took me a longer time to finish this book because my plan is not to just read through it, but also write the sample application along with it. At the end I’m proud to say that I’ve successfully coded the Yamba application.

Here is the list of useful links on this book:

  • Overview of this book from the publisher’s web site
  • On-line partial book preview
  • Forum to discuss about Learning Android by Marko Gargenta
  • Micro-blogging web site used for sample application
  • Personal note on the book content

  • Feb 21 2011

    Delayed Message When URL redirect for Oracle APEX application

    Category: APEX,Browser,PL/SQL,URLittichai @ 2:38 pm

    I’ve recently moved our internal APEX applications to a new environment. We have new URL for applications. During the transition, even though users are informed with new URL and asked to switch to it, we still want the old URL to redirect to new one for a period of time to ensure the smooth transition.

    Oracle APEX provides the redirect capability by making the application Unavailable then perform Redirect to URL. This feature can be found under the Availability section from Shared Components > Definition.

    The Unavailable (Redirect to URL) works well if we would maintain the old URL. When user enters the old URL, they will be automatically redirected to new one. The redirect happens very quickly.

    In our case, since the old URL will be retired, we’d would like users to be aware of the change. Before redirecting to new URL, we’d like to display a message informing about the move and asking them to take an appropriate action.

    To do this, instead of using Unavailable (Redirect to URL), I will use Unavailable (Status Shown with PL/SQL) instead.

    The PL/SQL block just simply writes a Javascript to perform redirect. We will give a 3-second delay for users to read the message before the redirect takes place.

    BEGIN
      htp.p ('<html>');
      htp.p ('<head>');
      htp.p ('<script type="text/javascript">');
      htp.p ('function delayed_redirect() {');
      htp.p ('  window.location = "http://newURL.company.com"');
      htp.p ('}');
      htp.p ('</script>');
      htp.p ('</head>');
      htp.p ('<body onLoad="setTimeout(''delayed_redirect()'', 3000)">');
      htp.p ('<h1>The application has moved.</h1>');
      htp.p ('<h2>The redirect will NOT work after 3/1/2011. Please bookmark the new URL.</h2>');
      htp.p ('</body>');
      htp.p ('</html>');
    END;
    

    Here is what will be displayed for about 3 seconds before going to the new site.

    Tags:


    Oct 06 2009

    The Access Control Lists to Network Services (e.g., UTL_HTTP, UTL_SMTP, UTL_TCP, etc.) in Oracle 11g

    Category: 11g,Database,PL/SQLittichai @ 8:43 pm

    This is one of the 11g features I read it once when it was first released but did not see its significance until now. Last week we just migrated an application from 9i to 11g. During a test of the send mail package using UTL_SMTP, we got this error, “ORA-24247: network access denied by access control list (ACL).” After a quick search, I’m in luck because I found a lot of articles written about this new 11g feature. However, I particularly find these two well-written concepts and samples from Arup Nanda’s Access Control Lists for UTL_TCP/HTTP/SMTP and Oracle-Base’s Fine-Grained Access to Network Services in Oracle Database 11g Release 1 very helpful.

    My sample here is from our test case:

    1. The send mail package which executes the UTL_SMTP failed.

    TEST_USER SQL> exec pkg_LoadStatus.SendMail('user@company.com', 'Test Subject', 'Hello World');
    
    ORA-24247: network access denied by access control list (ACL)
    ORA-06512: at "SYS.UTL_TCP", line 17
    ORA-06512: at "SYS.UTL_TCP", line 246
    ORA-06512: at "SYS.UTL_SMTP", line 115
    ORA-06512: at "SYS.UTL_SMTP", line 138
    ORA-06512: at "pkg_LoadStatus", line 283
    ORA-06512: at line 3

    2. To fix it, an ACL has to be created.

    The principal is the user or role to be added into this ACL. In this case, the TEST_USER account is added during the ACL creation. This field is case sensitive.

    SQL> connect / as sysdba
    
    begin
    dbms_network_acl_admin.create_acl (
    acl             => 'Mail_UTL_Access.xml',
    description     => 'Mail UTL Network Access',
    principal       => 'TEST_USER',
    is_grant        => TRUE,
    privilege       => 'connect',
    start_date      => null,
    end_date        => null
    );
    
    commit;
    end;
    /

    The description of each variable is clearly described in the Oracle-Base’s article.

    3. Verify a newly-created ACL.

    SQL> SELECT any_path
         FROM resource_view
         WHERE any_path like '/sys/acls/%.xml';
    
    ANY_PATH
    --------------------------------------------------------------------------------
    /sys/acls/Mail_UTL_Access.xml
    /sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN602a67cf3684e24e04403ba6c65c6_acl.xml
    /sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN602a67cf36e4e24e04403ba6c65c6_acl.xml
    /sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN602a67cf3724e24e04403ba6c65c6_acl.xml
    /sys/acls/OLAP_XS_ADMIN/OLAP_XS_ADMIN602a67cf3764e24e04403ba6c65c6_acl.xml
    /sys/acls/all_all_acl.xml
    /sys/acls/all_owner_acl.xml
    /sys/acls/bootstrap_acl.xml
    /sys/acls/ro_all_acl.xml
    /sys/acls/ro_anonymous_acl.xml

    4. Optionally you can add more users or roles into this ACL by using the add_privilege procedure. This is similar to the create_acl procedure except no description. Sample shown here is to add ADMIN_ADMIN_ROLE role.

    begin
    dbms_network_acl_admin.add_privilege (
    acl           => 'Mail_UTL_Access.xml',
    principal     => 'APP_ADMIN_ROLE',
    is_grant      => TRUE,
    privilege     => 'connect',
    start_date    => null,
    end_date      => null);
    
    commit;
    end;
    /

    5. Add a host and port range allowed.

    begin
    dbms_network_acl_admin.assign_acl (
    acl           => 'Mail_UTL_Access.xml',
    host          => 'smtp.company.com',
    lower_port    => 1,
    upper_port    => 1024);
    
    commit;
    end;
    /

    6. Test the send mail package again. This time there is no error, and the recipient receives email.

    TEST_USER SQL> exec pkg_LoadStatus.SendMail('user@company.com', 'Test Subject', 'Hello World');
    
    PL/SQL procedure successfully completed
    

    Tags: , , , , ,


    Mar 27 2009

    ILovePLSQLAnd.net

    Category: PL/SQLittichai @ 4:03 pm

    Steven Feuerstein created this “I LOVE PL/SQL, AND…” web site at ILovePLSQLAnd.net with the intention to collect the list of gaps/issues PL/SQL (his passion) currently has. In his recent post, he met with the PL/SQL developers at Oracle headquarter, and received confirmation that they really listen to inputs from his web site.

    Sharing the same passion for PL/SQL, I’d like to help spreading the word about this effort. Please visit ILovePLSQLAnd.net, and give your inputs  or vote on the enhancements you feel would benefit you the most.

    The fine print here is that there is no gaurantee, but you never know; your small voice can make a big difference.

    Tags: ,


    Jan 22 2009

    Good whitepaper “For Developers: Making Friends with the Oracle Database”

    Category: Database,Programmingittichai @ 2:34 pm

    I just read a good whitepaper titled “For Developers: Making Friends with the Oracle Database” by Cary Millsap. Cary makes an excellent point that most developers think of database as a black box. However, by progressively understanding Oracle kernel little by little, they can improve performance of their queries dramatically. I appreciate the way Cary explains how to read trace files. As well, he provides instructions for needed tools to accomplish the tasks.

    Tags: ,


    Sep 15 2008

    Programming for kids

    Category: Kids,Programmingittichai @ 7:53 pm

    I’ve been looking for a way to help my kid learning computer programming. My daughter and I tried out the trial version of “Phrogram” which is listed in the top hits when googling for “kid programming”. It is nice, well-made and powerful by just looking at provided samples. Its look & feel and language look a lot like Visual Basic. But I think it is still considered as intermediate to advanced levels because you have to know syntaxes and actually typing them in. It would be definitely something I’d like her to learn if she grows up a little bit.

    This week, I ran into this new open-source programming for kids called “Scratch” by MIT Media Lab. Not only scratchword “open source” interests me, the drag-n-drop feature makes it a lot easier to learn programming. Even though this is not really focusing on computer language learning, it, instead, emphasizes on developing design process skill which I think it is better in a long-term because it can universally apply not only to all programming languages but also other areas related to mathematic and science.

    The other nice thing is the ability to upload and share your project on the web site.

    Tags:


    Jun 09 2008

    Statistic Calculation – DBMS_STAT_FUNCS

    Category: PL/SQL,Programmingittichai @ 9:30 pm

    Currently I’m working on a project dealing with lot of statistic calculations particularly that of quartiles. First, I have no idea what it is. Thanks to Wiki for explanation. Now the tough part is to do the actual calculation. Fortunately, Oracle provides DBMS_STAT_FUNCS which is exactly what I’m looking for.

    List of available calculations -

    TYPE summaryType IS RECORD (
    count             NUMBER,
    min               NUMBER,
    max               NUMBER,
    range             NUMBER,
    mean              NUMBER,
    cmode             num_table,
    variance          NUMBER,
    stddev            NUMBER,
    quantile_5        NUMBER,
    quantile_25       NUMBER,
    median            NUMBER,
    quantile_75       NUMBER,
    quantile_95       NUMBER,
    plus_x_sigma      NUMBER,
    minus_x_sigma     NUMBER,
    extreme_values    num_table,
    top_5_values      n_arr,
    bottom_5_values   n_arr);

    Sample -

    set serveroutput on;
    DECLARE
    sfsumtype dbms_stat_funcs.summaryType;
    BEGIN
    dbms_stat_funcs.summary(p_ownername=>'SCHEMA_NAME',
                         p_tablename=>'TABLE_NAME',
                         p_columnname=>'COLUMN_NAME',
                         s=>sfsumtype);
    dbms_output.put_line('Quantile 5   => ' || sfsumtype.quantile_5);
    dbms_output.put_line('Quantile 25  => ' || sfsumtype.quantile_25);
    dbms_output.put_line('Median       => ' || sfsumtype.median);
    dbms_output.put_line('Quantile 75  => ' || sfsumtype.quantile_75);
    dbms_output.put_line('Quantile 95  => ' || sfsumtype.quantile_95);
    END;
    /

    Tags: ,