<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Android app development Phone</title>
	<atom:link href="http://phoneandcamera.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://phoneandcamera.com</link>
	<description>Best android phones</description>
	<lastBuildDate>Fri, 14 Oct 2011 12:42:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Getting Started with Testing</title>
		<link>http://phoneandcamera.com/2011/10/14/getting-started-with-testing/</link>
		<comments>http://phoneandcamera.com/2011/10/14/getting-started-with-testing/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 12:06:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://phoneandcamera.com/?p=6</guid>
		<description><![CDATA[Getting Started with Testing This chapter introduces the different types of testing and their applicability to software development projects in general and to Android in particular. We will avoid introductions to Android and the Open Handset Alliance (http://www.openhandsetalliance.com) as they are covered in many books already and I am inclined to believe that if you [...]]]></description>
			<content:encoded><![CDATA[<p>Getting Started with Testing</p>
<p>This chapter introduces the different types of testing and their applicability to software development projects in general and to <strong>Android</strong> in particular.</p>
<p>We will avoid introductions to Android and the <strong>Open Handset Alliance </strong>(http://www.openhandsetalliance.com) as they are covered in many books already and I am inclined to believe that if you are reading a book covering this more advanced topic you will have started with Android development before.</p>
<p>However, we will be reviewing the main concepts behind testing and the techniques, frameworks, and tools available to deploy your testing strategy on Android.</p>
<p><strong>Brief history</strong></p>
<p>Initially, when Android was introduced by the end of 2007, there was very little support for testing on the platform, and for some of us very accustomed to using testing as a component intimately coupled with the development process, it was time to start developing some frameworks and tools to permit this approach.</p>
<p>By that time Android had some rudimentary support for unit testing using JUnit (http://www.JUnit.org), but it was not fully supported and even less documented.</p>
<p>In the process of writing my own library and tools, I discovered Phil Smith&#8217;s <strong>Positron </strong>(originally at http://code.google.com/p/android-positron and now renamed and moved to http://code.google.com/p/autoandroid), an Open Source library and a very suitable alternative to support testing on Android, so I decided to extend his excellent work and bring some new and missing pieces to the table.</p>
<p>Some aspects of test automation were not included and I started a complementary project to fill that gap, it was consequently named <strong>Electron</strong>. And although positron is the anti-particle of the electron, and they annihilate if they collide, take for granted that that was not the idea, but more the conservation of energy and the generation of some visible light and waves.</p>
<p>Later on, Electron entered the first <strong>Android Development Challenge</strong> (<strong>ADC1</strong>) in early 2008 and though it obtained a rather good score in some categories, frameworks had no place in that competition. Should you be interested in the origin</p>
<p>of testing on Android, please find some articles and videos that were published in</p>
<p>my personal blog (http://dtmilano.blogspot.com/search/label/electron).</p>
<p>By that time Unit Tests could be run on Eclipse. However, testing was not done on the real target but on a JVM on the local development computer.</p>
<p>Google also provided application instrumentation code through the Instrumentation class. When running an application with instrumentation turned on, this class is instantiated for you before any of the application code, allowing you to monitor all of the interaction the system has with the application. An Instrumentation implementation is described to the system through an</p>
<p>AndroidManifest.xml file.</p>
<p>During those early stages in the Android development evolution, I started writing</p>
<p>some articles in my blog filling the gaps on testing. This book is the evolution and</p>
<p>completion of that work in an orderly and understandable manner to paradoxically let you be bitten by the Android testing bug.</p>
<p><strong>Software bugs</strong></p>
<p>It doesn&#8217;t matter how hard you try and how much time you invest in design and even how careful you are when programming, mistakes are inevitable and bugs will appear.</p>
<p>Bugs and software development are intimately related. However, the term <strong>bugs</strong> to</p>
<p>describe flaws, mistakes, or errors has been used in hardware engineering many</p>
<p>decades before even computers were invented. Notwithstanding the story about the term &#8216;bug&#8217; coined by Mark II operators at Harvard University, Thomas Edison wrote this in 1878 in a letter to Puskás Tivadar showing the early adoption of the term:</p>
<p><em>&#8220;It has been just so in all of my inventions. The first step is an intuition, and </em></p>
<p><em>comes with a burst, then difficulties arise—this thing gives out and [it is] then </em></p>
<p><em>that &#8216;Bugs&#8217;—as such little faults and difficulties are called—show themselves </em></p>
<p><em>and months of intense watching, study and labor are requisite before commercial </em></p>
<p><em>success or failure is certainly reached.&#8221;</em></p>
<p><strong>How bugs severely affect your projects </strong></p>
<p>Bugs affect many aspects of your software development project and it is clearly understood that the sooner in the process you find and <em>squash</em> them, the better. It doesn&#8217;t matter if you are developing a simple application to publish on the Android Market, re-branding the Android experience for an operator, or creating a customized version of Android for a device manufacturer, bugs will delay your shipment and will cost you money.</p>
<p>From all of the software development methodologies and techniques, <strong>Test Driven Development</strong>, an agile component of the software development process, is likely the one that forces you to face your bugs earlier in the development process and thus it is also likely that you will solve more problems up front.</p>
<p>Furthermore, the increase in productivity can be clearly appreciated in a project where a software development team uses this technique versus one that is, in the best of cases, writing tests at the end of the development cycle. If you have been involved in software development for the mobile industry, you will have reasons to believe that with all the rush this stage never occurs. It&#8217;s funny because, usually, this rush is to solve problems that could have been avoided.</p>
<p>In a study conducted by the <strong>National Institute of Standards and Technology</strong> (USA) in 2002, it was reported that software bugs cost the economy $59.5 billion annually. More than a third of this cost could be avoided if better software testing was performed.</p>
<p>But please, don&#8217;t misunderstand this message. There are no <em>silver bullets</em> in software development and what will lead you to an increase in productivity and manageability of your project is discipline in applying these methodologies and techniques to stay in control.</p>
<p><strong>Why, what, how, and when to test</strong></p>
<p>You should understand that early bug detection saves a huge amount of project resources and reduces software maintenance costs. This is the best known reason to write software tests for your development project. Increased productivity will soon be evident.</p>
<p>Additionally, writing the tests will give you a deeper understanding of the requirements and the problem to be solved. You will not be able to write tests for a piece of software you don&#8217;t understand.</p>
<p>This is also the reason behind the approach of writing tests to clearly understand</p>
<p>legacy or third party code and having the ability to confidently change or update it.</p>
<p>The more the code covered by your tests, the higher would be your expectations of discovering the hidden bugs.</p>
<p>If during this coverage analysis you find that some areas of your code are not</p>
<p>exercised, additional tests should be added to cover this code as well.</p>
<p>This technique requires a special instrumented Android build to collect probe data and must be disabled for any release code because the impact on performance could severely affect application behavior.</p>
<p>To fill this gap, enter EMMA (http://emma.sourceforge.net/), an open-source toolkit for measuring and reporting Java code coverage, that can offline instrument</p>
<p>classes for coverage. It supports various coverage types:</p>
<ul>
<li>class</li>
<li>method</li>
<li>line</li>
<li>basic block</li>
</ul>
<p>&nbsp;</p>
<p>Coverage reports can also be obtained in different output formats. EMMA is supported to some degree by the Android framework and it is possible to build an EMMA instrumented version of Android.</p>
<p>We will be analyzing the use of EMMA on Android to guide us to full test coverage of our code in <em>Chapter 10</em>, <em>Alternative Testing Tactics</em>.</p>
<p>This screenshot shows how an EMMA code coverage report is displayed in the Eclipse editor, showing green lines where the code has been tested, provided the corresponding plugin is installed.</p>
<p><em></em><a href="http://phoneandcamera.com/wp-content/uploads/2011/10/Android-testing-guide.jpg"><img class="aligncenter size-medium wp-image-7" title="Android testing guide" src="http://phoneandcamera.com/wp-content/uploads/2011/10/Android-testing-guide-300x149.jpg" alt="" width="300" height="149" /></a></p>
<p>Unfortunately, the plugin doesn&#8217;t support Android tests yet, so right now you can only use it for your JUnit tests. An Android coverage analysis report is only available through HTML.</p>
<p>Tests should be automated, and you should run some or all of them every time you introduce a change or addition to your code, in order to ensure that all the previous</p>
<p>conditions are still met and that the new code still satisfies the tests as expected.</p>
<p>This leads us to the introduction of <strong>Continuous Integration</strong>, which will be discussed in detail in <em>Chapter 8</em>, <em>Continuous Integration</em>. This relies on the automation of tests and building processes.</p>
<p>If you don&#8217;t use automated testing, it is practically impossible to adopt Continuous</p>
<p>Integration as part of the development process and it is very difficult to ensure that</p>
<p>changes do not break existing code.</p>
<p><strong>What to test </strong></p>
<p>Strictly speaking you should test every statement in your code but this also depends on different criteria and can be reduced to test the path of execution or just some methods. Usually there is no need to test something that can&#8217;t be broken, for example it usually makes no sense to test getters and setters as you probably won&#8217;t be testing the Java compiler on your own code and the compiler would have already performed its own tests.</p>
<p>In addition to the functional areas you should test, there are some specific areas of</p>
<p>Android applications that you should consider. We will be looking at these in the following sections.</p>
<p><strong>Activity lifecycle events </strong></p>
<p>You should test that your activities handle lifecycle events correctly.</p>
<p>If your activity should save its state during onPause() or onDestroy()events and later restore it in onCreate(BundlesavedInstanceState), you should be able to reproduce and test these conditions and verify that the state was correctly saved and restored.</p>
<p>Configuration-changed events should also be tested as some of these events cause</p>
<p>the current Activity to be recreated, and you should test for correct handling of the</p>
<p>event and that the newly created Activity preserves the previous state. Configuration</p>
<p>changes are triggered even by rotation events, so you should test your application&#8217;s ability to handle these situations.</p>
<p><strong>Database and filesystem operations </strong></p>
<p>Database and filesystem operations should be tested to ensure that they are handled</p>
<p>correctly. These operations should be tested in isolation at the lower system level, at a higher level through ContentProviders, and from the application itself.</p>
<p>To test these components in isolation, Android provides some mock objects in the android.test.mock package.</p>
<p><strong>Physical characteristics of the device </strong></p>
<p>Well before delivering your application you should be sure that all of the different devices it can be run on are supported or at the least you should detect the situation and take appropriate measures.</p>
<p>Among other characteristics of the devices, you may find that you should test:<!--[if gte mso 9]><xml><br />
<w:WordDocument><br />
<w:View>Normal</w:View><br />
<w:Zoom>0</w:Zoom><br />
<w:TrackMoves/><br />
<w:TrackFormatting/><br />
<w:PunctuationKerning/><br />
<w:ValidateAgainstSchemas/><br />
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid><br />
<w:IgnoreMixedContent>false</w:IgnoreMixedContent><br />
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText><br />
<w:DoNotPromoteQF/><br />
<w:LidThemeOther>EN-US</w:LidThemeOther><br />
<w:LidThemeAsian>X-NONE</w:LidThemeAsian><br />
<w:LidThemeComplexScript>TH</w:LidThemeComplexScript><br />
<w:Compatibility><br />
<w:BreakWrappedTables/><br />
<w:SnapToGridInCell/><br />
<w:ApplyBreakingRules/><br />
<w:WrapTextWithPunct/><br />
<w:UseAsianBreakRules/><br />
<w:DontGrowAutofit/><br />
<w:SplitPgBreakAndParaMark/><br />
<w:DontVertAlignCellWithSp/><br />
<w:DontBreakConstrainedForcedTables/><br />
<w:DontVertAlignInTxbx/><br />
<w:Word11KerningPairs/><br />
<w:CachedColBalance/><br />
<w:UseFELayout/><br />
</w:Compatibility><br />
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><br />
<m:mathPr><br />
<m:mathFont m:val="Cambria Math"/><br />
<m:brkBin m:val="before"/><br />
<m:brkBinSub m:val="--"/><br />
<m:smallFrac m:val="off"/><br />
<m:dispDef/><br />
<m:lMargin m:val="0"/><br />
<m:rMargin m:val="0"/><br />
<m:defJc m:val="centerGroup"/><br />
<m:wrapIndent m:val="1440"/><br />
<m:intLim m:val="subSup"/><br />
<m:naryLim m:val="undOvr"/><br />
</m:mathPr></w:WordDocument><br />
</xml><![endif]--><!--[if gte mso 9]><xml><br />
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"><br />
<w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal"/><br />
<w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/><br />
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 1"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 2"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 3"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 4"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 5"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 6"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 7"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 8"/><br />
<w:LsdException Locked="false" Priority="39" Name="toc 9"/><br />
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/><br />
<w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title"/><br />
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/><br />
<w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/><br />
<w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong"/><br />
<w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/><br />
<w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid"/><br />
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/><br />
<w:LsdException Locked="false" Priority="1" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/><br />
<w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading"/><br />
<w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List"/><br />
<w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid"/><br />
<w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1"/><br />
<w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2"/><br />
<w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1"/><br />
<w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2"/><br />
<w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1"/><br />
<w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2"/><br />
<w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3"/><br />
<w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List"/><br />
<w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading"/><br />
<w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List"/><br />
<w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid"/><br />
<w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1"/><br />
<w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1"/><br />
<w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1"/><br />
<w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/><br />
<w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/><br />
<w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/><br />
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/><br />
<w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/><br />
<w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote"/><br />
<w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/><br />
<w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/><br />
<w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/><br />
<w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/><br />
<w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/><br />
<w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1"/><br />
<w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/><br />
<w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1"/><br />
<w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/><br />
<w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2"/><br />
<w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2"/><br />
<w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2"/><br />
<w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/><br />
<w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/><br />
<w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/><br />
<w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/><br />
<w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/><br />
<w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/><br />
<w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/><br />
<w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2"/><br />
<w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/><br />
<w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2"/><br />
<w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/><br />
<w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3"/><br />
<w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3"/><br />
<w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3"/><br />
<w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/><br />
<w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/><br />
<w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/><br />
<w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/><br />
<w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/><br />
<w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/><br />
<w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/><br />
<w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3"/><br />
<w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/><br />
<w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3"/><br />
<w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/><br />
<w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4"/><br />
<w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4"/><br />
<w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4"/><br />
<w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/><br />
<w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/><br />
<w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/><br />
<w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/><br />
<w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/><br />
<w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/><br />
<w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/><br />
<w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4"/><br />
<w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/><br />
<w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4"/><br />
<w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/><br />
<w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5"/><br />
<w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5"/><br />
<w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5"/><br />
<w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/><br />
<w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/><br />
<w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/><br />
<w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/><br />
<w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/><br />
<w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/><br />
<w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/><br />
<w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5"/><br />
<w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/><br />
<w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5"/><br />
<w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/><br />
<w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6"/><br />
<w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6"/><br />
<w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6"/><br />
<w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/><br />
<w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/><br />
<w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/><br />
<w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/><br />
<w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/><br />
<w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/><br />
<w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/><br />
<w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6"/><br />
<w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/><br />
<w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6"/><br />
<w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/><br />
<w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/><br />
<w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/><br />
<w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/><br />
<w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/><br />
<w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title"/><br />
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/><br />
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/><br />
</w:LatentStyles><br />
</xml><![endif]--><!--[if gte mso 10]></p>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:ตารางปกติ;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
mso-bidi-font-size:14.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Cordia New";
mso-bidi-theme-font:minor-bidi;}
</style>
<p><![endif]--></p>
<p class="Default" style="margin: 0cm 0cm 1.25pt; text-indent: 0cm;">• Network capabilities<br />
• Screen densities<br />
• Screen resolutions<br />
• Screen sizes<br />
• Availability of sensors</p>
<p class="Default" style="margin: 0cm 0cm 1.25pt; text-indent: 0cm;">• Keyboard and other input devices<br />
• GPS<br />
• External storage</p>
<p class="Default" style="margin-left: 0cm; text-indent: 0cm;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif'; color: windowtext;">nal storage </span></p>
<p class="Default"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif'; color: windowtext;"> </span></p>
<p class="CM3" style="margin-right: 10pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">In this respect Android Virtual Devices play an important role because it is practically impossible to have access to all possible devices with all of the possible </span></p>
<p class="CM8" style="margin-right: 6.35pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">combinations of features but you can configure AVD for almost every situation. However, as was mentioned before, save your final testing for actual devices where </span></p>
<p class="CM154" style="margin-bottom: 17.5pt; line-height: 12.65pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">real users will run the application to understand its behavior. </span></p>
<p class="CM149" style="margin-bottom: 3.6pt;"><strong><span style="font-size: 20pt; font-family: 'Arial','sans-serif';">Types of tests</span></strong></p>
<p class="CM8" style="margin-right: 6.35pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">Testing can be implemented at any time in the development process, depending on the method employed. However, we will be promoting testing at an early stage of </span></p>
<p class="CM2"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">the development effort, even before the full set of requirements have been defined </span></p>
<p class="CM148" style="margin-bottom: 8.6pt; line-height: 12.65pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">and the coding process has been started. </span></p>
<p class="CM150" style="margin: 0cm 14pt 14.85pt 0cm; line-height: 12.65pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">There are several types of test available depending on the object being tested. Regardless of its type, a test should verify a condition and return the result of this evaluation as a single Boolean value indicating success or failure. </span></p>
<p class="CM149" style="margin-bottom: 3.6pt;"><strong><span style="font-size: 18pt; font-family: 'Arial','sans-serif';">Unit tests </span></strong></p>
<p class="CM148" style="margin-bottom: 8.6pt; line-height: 12.65pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">Unit tests are software tests written by programmers for programmers in a programming language and they should isolate the component under test and be able to test it in a repeatable way. That&#8217;s why unit tests and mock objects are usually placed together. You use mock objects to isolate the unit from its dependencies, to monitor interactions, and also to be able to repeat the test any number of times. For example, if your test deletes some data from a database you probably don&#8217;t want the data to be actually deleted and not found the next time the test is run. </span></p>
<p class="CM148" style="margin: 0cm 18.75pt 8.6pt 0cm; line-height: 12.65pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">JUnit is the de-facto standard for unit tests on Android. It&#8217;s a simple open source framework for automating unit testing, originally written by Erich Gamma and Kent Beck. </span></p>
<p class="CM148" style="margin: 0cm 22.25pt 8.6pt 0cm; line-height: 12.65pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">Android (up to Android 2.3 Gingerbread) uses JUnit 3. This version doesn&#8217;t use annotations and uses introspection to detect the tests. </span></p>
<p class="CM148" style="margin-bottom: 8.6pt; line-height: 12.65pt;"><span style="font-size: 10.5pt; font-family: 'Book Antiqua','serif';">A typical JUnit test would look something like this (the actual tests are highlighted): </span></p>
<p class="CM39" style="margin-left: 18pt;"><span style="color: #999999;"><em><span style="font-size: 9pt; font-family: 'Courier Std','serif';">/**</span></em></span></p>
<h6 class="Default" style="margin-left: 23.35pt;"><span style="color: #999999;"><em><span style="font-size: 9pt; font-family: 'Courier Std','serif';"> * Android Application Testing Guide</span></em></span></h6>
<h6 class="CM148" style="margin: 0cm 0cm 8.6pt 18pt; text-indent: 5.35pt; line-height: 12pt;"><span style="color: #999999;"><em><span style="font-size: 9pt; font-family: 'Courier Std','serif';"> */ package com.example.aatg.test; </span></em></span></h6>
<h6><span style="color: #999999;"><em>import JUnit.framework.TestCase; /**</em></span></h6>
<h6><span style="color: #999999;"><em> * @author diego */ public class MyUnitTests extends TestCase {</em></span></h6>
<h6><span style="color: #999999;"><em> private int mFixture; /**</em></span></h6>
<h6><span style="color: #999999;"><em> * @param name test name */ public MyUnitTests(String name) { super(name);</em></span></h6>
<h6><span style="color: #999999;"><em> } /* (non-Javadoc)</em></span></h6>
<h6><span style="color: #999999;"><em> * @see JUnit.framework.TestCase#setUp() */</em></span></h6>
<h6><span style="color: #999999;"><em> protected void setUp() throws Exception { super.setUp(); mFixture = 1234;</em></span></h6>
<h6><span style="color: #999999;"><em> } /* (non-Javadoc)</em></span></h6>
<h6><span style="color: #999999;"><em> * @see JUnit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown();</em></span></h6>
<h6><span style="color: #999999;"><em> } /**</em></span></h6>
<h6><span style="color: #999999;"><em> * Preconditions */</em></span></h6>
<h6><span style="color: #999999;"><em><strong> public void testPreconditions() { } </strong></em></span></h6>
<h6><span style="color: #999999;"><em>/**</em></span></h6>
<h6><span style="color: #999999;"><em> * Test method */</em></span></h6>
<h6><span style="color: #999999;"><em><strong> public void testSomething() { fail(&#8220;Not implemented yet&#8221;); } </strong></em></span></h6>
<p><span style="color: #999999;"><em>}</em></span></p>
<p><strong>Downloading the example code </strong></p>
<p>You can download the example code files for all Packt books you have</p>
<p>purchased from your account at <strong>http://www.PacktPub.com.</strong> If you purchased this book elsewhere, you can visit <strong>http://www.PacktPub. com/</strong>supportand register to have the files e-mailed directly to you</p>
<p>The following sections explain in detail the components that build up our test case.</p>
<p><strong>The test fixture </strong></p>
<p>A test fixture is the well known state defined as a baseline to run the tests and is</p>
<p>shared by all the test cases, and thus plays a fundamental role in the design of the tests.</p>
<p>Generally it is implemented as a set of member variables and, following Android conventions, they will have names starting with m, for example mActivity.</p>
<p>However, it can also contain external data, as specific entries in a database or files present in the filesystem.</p>
<p><strong>The setUp() method </strong></p>
<p>This method is called to initialize the fixture.</p>
<p>Overriding it you have the opportunity to create objects and initialize fields that</p>
<p>will be used by tests. It&#8217;s worth noting that this setup occurs <em>before</em> every test.</p>
<p><strong>The tearDown() method </strong></p>
<p>This method is called to finalize the fixture.</p>
<p>Overriding it you can release resources used by the initialization or tests. Again, this method is invoked <em>after</em> every test.</p>
<p>For example, you can release a database or a network connection here.</p>
<p>JUnit is designed in such a way that the entire tree of test instances is built in one pass, and then the tests are executed in a second pass. Therefore, the test runner holds strong references to all Test instances for the duration of the test execution. This means that for very large and very long test runs with many Test instances, none of the tests may be garbage collected until the end of the entire test run. This is particularly important in Android and when testing on limited devices as some tests may fail not because of an intrinsic problem but because of the amount of memory needed to run the application plus its tests exceeding the device limits.</p>
<p>Therefore, if you allocate external or limited resources in a test, such as Services or ContentProviders, you are responsible for freeing those resources. Explicitly setting an object to null in the tearDown()method, for example, allows it to be garbage collected before the end of the entire test run.</p>
<p><strong>Test preconditions </strong></p>
<p>Usually there is no way to test for preconditions as the tests are discovered using introspection and their order could vary. So it&#8217;s customary to create a testPreconditions() method to test for preconditions. Though there is no</p>
<p>assurance that this test will be called in any specific order, it is good practice to keep</p>
<p>this and the preconditions together for organizational purposes.</p>
<p><strong>The actual tests </strong></p>
<p>All publicvoid methods whose names start with test will be considered as a test. JUnit 3, as opposed to JUnit 4, doesn&#8217;t use annotations to discover the tests</p>
<p>but introspection to find their names. There are some annotations available on the</p>
<p>Android test framework such as @SmallTest, @MediumTest, and @LargeTest, but they don&#8217;t turn a simple method into a test. Instead they organize them in different categories. Ultimately you will have the ability to run tests for a single category using the test runner.</p>
<p>As a rule of thumb, name your tests in a descriptive way using nouns and the condition being tested.</p>
<p>For example: testValues(), testConversionError(), testConversionToString() are all valid test names.</p>
<p>Test for exceptions and wrong values instead of just testing for positive cases.</p>
<p>During the execution of the test some conditions, side effects, or method returns should be compared against the expectations. To ease these operations, JUnit provides a full set of assert* methods to compare the expected results from the test to the actual results after running with them throwing exceptions if conditions are not met. Then the test runner handles these exceptions and presents the results.</p>
<p>These methods, which are overloaded to support different arguments, include:</p>
<ul>
<li>assertEquals()</li>
<li>assertFalse()</li>
<li>assertNotNull()</li>
<li>assertNotSame()</li>
<li>assertNull()</li>
<li>assertSame()</li>
<li>assertTrue()</li>
<li>fail()</li>
</ul>
<p>In addition to these JUnit assert methods, Android extends Assert in two specialized classes providing additional tests:</p>
<p>• MoreAsserts<br />
• ViewAsserts</p>
<p><strong>Mock objects</strong><br />
Mock objects are mimic objects used instead of calling the real domain objects toenable testing units in isolation.</p>
<p>Generally, this is done to ensure that correct methods are called but they can also be of help, as mentioned, to isolate your tests from the surrounding universe and enable you to run them independently and repeatably.</p>
<p>The Android testing framework supports several mock objects that you will find very useful when writing your tests but you will need to provide some dependencies<br />
to be able to compile the tests.</p>
<p>Several classes are provided by the Android testing framework in the android.</p>
<p><strong>UI tests </strong></p>
<p>Finally, special consideration should be taken if your tests involve UI components. As you may have already known, only the main thread is allowed to alter the UI in Android. Thus a special annotation @UIThreadTest is used to indicate that a particular test should be run on that thread and would have the ability to alter the UI. On the other hand, if you only want to run parts of your test on the UI thread, you may use the Activity.runOnUiThread(Runnabler) method providing the corresponding Runnable containing testing instructions.</p>
<p>A helper class TouchUtils is also provided to aid in the UI test creation allowing the generation of events to send to the Views, such as:</p>
<ul>
<li>click</li>
<li>drag</li>
<li>long click</li>
<li>scroll</li>
<li>tap</li>
<li>touch</li>
</ul>
<p>&nbsp;</p>
<p>By these means you can actually remote control you application from the tests.</p>
<p><strong>Eclipse and other IDE support </strong></p>
<p>JUnit is fully supported by Eclipse and the Android ADT plugin lets you create Android testing projects. Furthermore, you can run the tests and analyze the results without leaving the IDE.</p>
<p>This also provides a more subtle advantage; being able to run the tests from Eclipse</p>
<p>allows you to debug the tests that are not behaving correctly.</p>
<p>In the screenshot, we can see how Eclipse runs <strong>18 tests</strong> taking 20.008 seconds, where <strong>0 Errors</strong> and <strong>0 Failure</strong>s were detected. The name of each test and its duration is also displayed. If there was a failure, the <strong>Failure Trace</strong> would show the related information.</p>
<p><a href="http://phoneandcamera.com/wp-content/uploads/2011/10/Failure-Trace.jpg"><img class="aligncenter size-medium wp-image-14" title="Failure Trace" src="http://phoneandcamera.com/wp-content/uploads/2011/10/Failure-Trace-190x300.jpg" alt="" width="190" height="300" /></a>Other IDEs like ItelliJ and Netbeans have plugins integrating Android development</p>
<p>to some degree but they are not officially supported.</p>
<p>Even if you are not developing in an IDE, you can find support to run the tests with</p>
<p>ant (check http://ant.apache.org if you are not familiar with this tool). This setup is done by the android command using the subcommand createtest-project as described by this help text:</p>
<p>$ android &#8211;help create test-project</p>
<p>Usage: android [global options] create test-project [action options]</p>
<p>Global options: -v &#8211;verbose Verbose mode: errors, warnings and informational messages</p>
<p>are printed. -h &#8211;help Help on a specific command. -s &#8211;silent Silent mode: only errors are printed out.</p>
<p>Action &#8220;create test-project&#8221;:</p>
<p>Creates a new Android project for a test package. Options:</p>
<p>-p &#8211;path The new project&#8217;s directory [required]</p>
<p>-m &#8211;main Path to directory of the app under test, relative to the</p>
<p>test project directory [required] -n &#8211;name Project name</p>
<p>As indicated by the help you should provide at least the path to the project (&#8211;path) and the path to the main project or the project under test (&#8211;main)<br />
<strong>Integration tests</strong><br />
Integration tests are designed to test the way individual components work jointly. Modules that have been unit tested independently are now combined together to test the integration.</p>
<p>Usually Android Activities require some integration with the system infrastructure to be able to run. They need the Activity lifecycle provided by the ActivityManager,</p>
<p>and access to resources, filesystem, and databases.</p>
<p>The same criteria apply to other Android components like Services or ContentProviders that need to interact with other parts of the system to achieve their function.</p>
<p>In all these cases there are specialized tests provided by the Android testing framework that facilitate the creation of tests for these components.<br />
<strong>Functional or acceptance tests</strong><br />
In agile software development, functional or acceptance tests are usually created by business and Quality Assurance (QA) people and expressed in a business domain language. These are high level tests to test the completeness and correctness of a user requirement or feature. They are created ideally through collaboration between business customers, business analysts, QA, testers, and developers. However the business customers (product owners) are the primary owners of these tests.</p>
<p>Some frameworks and tools can help in this field, most notably FitNesse (http:// www.fitnesse.org), which can be easily integrated, up to a point, into the Android development process and will let you create acceptance tests and check their results.</p>
<p align="justify"><span style="font-size: xx-small;">so check Fit, http://fit.c2.com and Slim (Simple List Invocation Method), http://fitnesse.org/FitNesse.UserGuide.SliM, as an alternative to Fit. </span></p>
<p><span style="color: #000000; font-size: xx-small;"><span style="color: #000000; font-size: xx-small;"><span style="font-size: small;"><span style="font-size: small;"><span style="font-size: small;"><span style="font-size: x-small;"><span style="font-size: x-small;"><span style="font-size: x-small;"><span style="font-size: xx-small;"><span style="font-size: xx-small;"><span style="font-size: xx-small;"><span style="font-size: xx-small;"><a href="http://phoneandcamera.com/wp-content/uploads/2011/10/Behavior-Driven-Development.jpg"><img class="aligncenter size-medium wp-image-16" title="Behavior Driven Development" src="http://phoneandcamera.com/wp-content/uploads/2011/10/Behavior-Driven-Development-300x232.jpg" alt="" width="300" height="232" /></a><br />
</span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span>Lately, a new trend named <strong>Behavior Driven Development</strong> has gained some popularity and in a very brief description can be understood as the evolution of Test Driven Development. It aims to provide a common vocabulary between business and technology people in order to increase mutual understanding. </span></p>
<p><span>Behavior Driven Development can be expressed as a framework of activities based on three principles (more information can be found at <span>http://behaviour-driven. org<span style="font-size: xx-small;">): </span></span></span></p>
<ul type="disc">
<li><span><span style="font-size: xx-small;"><span>Business and technology should refer to the same system in the same way </span></span></span></li>
<li><span><span style="font-size: xx-small;"><span style="font-size: xx-small;">Any system should have an identified, verifiable value to the business </span></span></span></li>
<li><span><span style="font-size: xx-small;"><span>Upfront analysis, design, and planning all have a diminishing return </span></span></span></li>
</ul>
<p>To apply these principles, business people are usually involved in writing test case scenarios in a high level language and use some tool, such as <strong>jbehave </strong>(http://jbehave.org). In the following example, these scenarios are translated into code that expresses the same test scenario in a programming language.</p>
<p><strong>Test case scenario </strong></p>
<p>As an illustration of this technique here is an oversimplified example.</p>
<h6>This scenario is:<br />
<span style="color: #99cc00;">Given I&#8217;m using the Temperature Converter.</span><br />
<span style="color: #99cc00;">When I enter 100 into Celsius field.</span><br />
<span style="color: #99cc00;">Then I obtain 212 in Fahrenheit field.</span><br />
<span style="color: #99cc00;">It would be translated into something similar to:</span><br />
<span style="color: #99cc00;">@Given(&#8220;I am using the Temperature Converter&#8221;)</span><br />
<span style="color: #99cc00;">public void createTemperatureConverter() {</span><br />
<span style="color: #99cc00;">// do nothing</span><br />
<span style="color: #99cc00;">}</span><br />
<span style="color: #99cc00;">@When(&#8220;I enter $celsius into Celsius field&#8221;)</span><br />
<span style="color: #99cc00;">public void setCelsius(int celsius) {</span><br />
<span style="color: #99cc00;">mCelsius= celsius;</span><br />
<span style="color: #99cc00;">}</span><br />
<span style="color: #99cc00;">@Then(&#8220;I obtain $fahrenheit in Fahrenheit field&#8221;)</span><br />
<span style="color: #99cc00;">public void testCelsiusToFahrenheit(int fahrenheit) {</span><br />
<span style="color: #99cc00;">assertEquals(fahrenheit,</span><br />
<span style="color: #99cc00;">TemperatureConverter.celsiusToFahrenheit</span><br />
<span style="color: #99cc00;">(mCelsius));</span><br />
<span style="color: #99cc00;">}</span></h6>
<p><strong>Performance tests </strong><strong></strong></p>
<p>Performance tests measure performance characteristics of the components in a repeatable way. If performance improvements are required by some part of the application, the best approach is to measure performance before and after some change is introduced.</p>
<p>As is widely known, premature optimization does more harm than good, so it is better to clearly understand the impact of your changes on the overall performance.</p>
<p>The introduction of the <strong>Dalvik JIT</strong> compiler in Android 2.2 changed some optimization patterns that were widely used in Android development. Nowadays, every recommendation about performance improvements on the Android developer&#8217;s site is backed up by performance tests.</p>
<p><strong>System tests </strong><strong></strong></p>
<p>The system is tested as a whole and the interaction between the components, software and hardware, is exercised. Normally, system tests include additional classes of tests like:</p>
<ul>
<li>GUI tests</li>
<li>Smoke tests</li>
<li>Performance tests</li>
<li>Installation tests</li>
</ul>
<p><strong>Android testing framework</strong><strong></strong></p>
<p>Android provides a very advanced testing framework extending the industry</p>
<p>standard JUnit with specific features suitable for implementing all of the testing</p>
<p>strategies and types we mentioned before. In some cases, additional tools are needed but the integration of these tools is in most cases simple and straightforward.</p>
<p>The key features of the Android testing environment include:</p>
<ul>
<li>Android extensions to the JUnit framework that provide access to Android system objects.</li>
<li>An instrumentation framework that lets tests control and examine the application.</li>
<li>Mock versions of commonly used Android system objects.</li>
<li>Tools for running single tests or test suites, with or without instrumentation.</li>
<li>Support for managing tests and test projects in the ADT Plugin for Eclipse and at the command line.</li>
</ul>
<p><strong>Instrumentation </strong><strong></strong></p>
<p>The instrumentation framework is the foundation of the testing framework. Instrumentation controls the application under test and permits the injection of mock components required by the application to run. For example, you can create mock Contexts before the application starts and let the application use them.</p>
<p>The introduction of the <strong>Dalvik JIT </strong>compiler in Android 2.2 changed some optimization patterns that were widely used in Android development. Nowadays, every recommendation about performance improvements on the Android developer&#8217;s site is backed up by performance tests.</p>
<p><strong>System tests </strong></p>
<p>The system is tested as a whole and the interaction between the components, software and hardware, is exercised. Normally, system tests include additional classes of tests like:</p>
<ul>
<li>GUI tests</li>
<li>Smoke tests</li>
<li>Performance tests</li>
<li>Installation tests</li>
</ul>
<p>&nbsp;</p>
<p><strong>Android testing framework </strong></p>
<p>Android provides a very advanced testing framework extending the industry</p>
<p>standard JUnit with specific features suitable for implementing all of the testing</p>
<p>strategies and types we mentioned before. In some cases, additional tools are needed but the integration of these tools is in most cases simple and straightforward.</p>
<p>The key features of the Android testing environment include:</p>
<ul>
<li>Android extensions to the JUnit framework that provide access to Android system objects.</li>
<li>An instrumentation framework that lets tests control and examine the application.</li>
<li>Mock versions of commonly used Android system objects.</li>
<li>Tools for running single tests or test suites, with or without instrumentation.</li>
<li>Support for managing tests and test projects in the ADT Plugin for Eclipse and at the command line.</li>
</ul>
<p>&nbsp;</p>
<p><strong>Instrumentation </strong></p>
<p>The instrumentation framework is the foundation of the testing framework. Instrumentation controls the application under test and permits the injection of mock components required by the application to run. For example, you can create mock Contexts before the application starts and let the application use them.</p>
<p>All interaction of the application with the surrounding environment can be controlled using this approach. You can also isolate your application in a restricted environment to be able to predict the results, forcing the values returned by some methods or mocking persistent and unchanged data for ContentProvider,</p>
<p>databases, or even the filesystem content.</p>
<p>A standard Android project has its tests in a correlated project that usually has the same project name but ends with <strong>Test</strong>. Inside this Test project, the AndroidManifest.xml declares the Instrumentation.</p>
<p>As an illustrative example, assume your project has a manifest like this:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt; &lt;manifest xmlns:android=&#8221;http://schemas.android.com/apk/res/android&#8221;</p>
<p><strong>package=&#8221;com.example.aatg.sample&#8221; </strong></p>
<p>android:versionCode=&#8221;1&#8243;android:versionName=&#8221;1.0&#8243;&gt;&lt;application android:icon=&#8221;@drawable/icon&#8221;</p>
<p>android:label=&#8221;@string/app_name&#8221;&gt; &lt;activity android:name=&#8221;.SampleActivity&#8221; android:label=&#8221;@string/app_name&#8221;&gt;</p>
<p>&lt;intent-filter&gt; &lt;action android:name=&#8221;android.intent.action.MAIN&#8221; /&gt; &lt;category android:name=</p>
<p>&#8220;android.intent.category.LAUNCHER&#8221; /&gt;&lt;/intent-filter&gt;&lt;/activity&gt;&lt;/application&gt;&lt;uses-sdk android:minSdkVersion=&#8221;7&#8243; /&gt; &lt;/manifest&gt;</p>
<p>In this case, the correlated Test project will have the following AndroidManifest.xml:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt; &lt;manifest xmlns:android=&#8221;http://schemas.android.com/apk/res/android&#8221;</p>
<p><strong>package=&#8221;com.example.aatg.sample.test&#8221; </strong></p>
<p>android:versionCode=&#8221;1&#8243; android:versionName=&#8221;1.0&#8243;&gt;&lt;application android:icon=&#8221;@drawable/icon&#8221;android:label=&#8221;@string/app_name&#8221;&gt;</p>
<p><strong>&lt;uses-library android:name=&#8221;android.test.runner&#8221; /&gt; </strong></p>
<p>&lt;/application&gt;&lt;uses-sdk android:minSdkVersion=&#8221;7&#8243; /&gt;</p>
<p><strong>&lt;instrumentationandroid:targetPackage=&#8221;com.example.aatg.sample&#8221;</strong></p>
<p><strong>android:name=&#8221;android.test.InstrumentationTestRunner&#8221; android:label=&#8221;Sample Tests&#8221; /&gt; </strong></p>
<p>&lt;uses-permission android:name=&#8221; android.permission.INJECT_EVENTS&#8221; /&gt; &lt;/manifest&gt;</p>
<p>Here the Instrumentation package is the same package as the main application with the .test suffix added.</p>
<p>Then the Instrumentation is declared specifying the target package and the test runner, in this case the default custom runner android.test. InstrumentationTestRunner.</p>
<p>Also notice that both, the application under test and the tests are Android applications with their corresponding APKs installed. Internally, they will be sharing the same process and thus have access to the same set of features.</p>
<p>When you run a test application, the <strong>Activity Manager </strong>(http://developer. android.com/intl/de/reference/android/app/ActivityManager.html) uses the instrumentation framework to start and control the test runner, which in turn uses instrumentation to shut down any running instances of the main application, starts the test application, and then starts the main application in the same process. This allows various aspects of the test application to work directly with the main application.</p>
<p><strong>Test targets </strong></p>
<p>During the evolution of your development project your tests would be targeted to</p>
<p>different devices. From the simplicity, flexibility, and speed of testing on an emulator to the unavoidable final testing on the specific devices you intend your application to</p>
<p>be run on, you should be able to run on all of them.</p>
<p>There are also some intermediate cases like running your tests on a local <strong>JVM </strong>virtual machine on the development computer or on a <strong>Dalvik </strong>virtual machine or Activity, depending on the case.</p>
<p>Every case has its pros and cons, but the good news is that you have all of these alternatives available to run your tests.</p>
<p>The emulator is probably the most powerful target as you can modify almost</p>
<p>every parameter from its configuration to simulate different conditions for your</p>
<p>tests. Ultimately, your application should be able to handle all of these situations, so it is much better to discover the problems upfront than when the application has been delivered.</p>
<p>The real devices are a requirement for performance tests, as it is somewhat difficult</p>
<p>to extrapolate performance measurements from a simulated device. You will discover the real user experience only when using the real device. Rendering,</p>
<p>scrolling, flinging, and other cases should be tested before delivering the application.</p>
<p><strong>Summary </strong></p>
<p>We have reviewed the main concepts behind testing in general and Android in particular. Having acquired this knowledge will let us start our journey and start</p>
<p>exploiting the benefits of testing in our software development projects.</p>
<p>So far, we have visited the following subjects:</p>
<ul>
<li>We reviewed the early stages of testing on Android and mentioned some of the frameworks that created the current alternatives.</li>
<li>We briefly analyzed the reasons behind testing and the whys, whats, hows,</li>
</ul>
<p>&nbsp;</p>
<p>and whens of it. Furthermore, from now on we will concentrate on exploring the hows, as we can assume that you are convinced by the arguments presented.</p>
<p>• We enumerated the different and most common types of tests you would need in your projects, described some of the tools we can count on our testing toolbox, and provided an introductory example of a JUnit unit test to better understand what we are discussing.</p>
<p>We also analyzed these techniques from the Android perspective and mentioned the use of Instrumentation to run our Android tests.</p>
<p>Now we will start analyzing the mentioned techniques, frameworks, and tools in detail, along with examples of their usage.</p>
]]></content:encoded>
			<wfw:commentRss>http://phoneandcamera.com/2011/10/14/getting-started-with-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: phoneandcamera.com @ 2012-02-23 01:56:20 -->
