ANDROID – TESTING L. Grewe. With the AndroidStudio IDE.

Slides:



Advertisements
Similar presentations
JUnit Tutorial Hong Qing Yu Nov JUnit Tutorial The testing problems The framework of JUnit A case study JUnit tool Practices.
Advertisements

Unit Testing Australian Development Centre Brisbane, Australia.
Content Testing In Eclipse, with ADT Android Testing Framework
J-Unit Framework.
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
Unit and Functional Testing with JUnit and Related Tools Greg Barnes University of Washington
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
Approach of Unit testing with the help of JUnit Satish Mishra
The Android Development Environment.  Getting started on the Android Platform  Installing required libraries  Programming Android using the Eclipse.
JUnit. What is unit testing? A unit is the smallest testable part of an application. A unit test automatically verifies the correctness of the unit. There.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
Android: Hello World Frank Xu Gannon University. Steps Configuration ▫Android SDK ▫Android Development Tools (ADT)  Eclipse plug-in ▫Android SDK and.
Android Life Cycle CS328 Dick Steflik. Life Cycle The steps that an application goes through from starting to finishing Slightly different than normal.
JUnit, Revisited 17-Apr-17.
Writing a Unit test Using JUnit At the top of the file include: import junit.framework.TestCase; The main class of the file must be: public Must extend.
1 Plug-in Development Environment (PDE) Guide. 2 Introduction to PDE l What is PDE: »a tool designed to help you develop platform plug-ins while working.
14-Jul-15 JUnit 4. Comparing JUnit 3 to JUnit 4 All the old assertXXX methods are the same Most things are about equally easy JUnit 4 makes it easier.
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
CSE 403 Lecture 15 UI Automation / Functional Testing Reading: How to Break Software, Ch. 2, Whittaker slides created by Marty Stepp
Programmer Testing Testing all things Java using JUnit and extensions.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Lesson 7 Unit Testing /JUnit/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
© 2005 by IBM; made available under the EPL v1.0 | March 1, 2005 Tim deBoer Gorkem Ercan Extend WTP Server Tools for your.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Testing with Android Part I of II. Android Testing Framework Based on JUnit The Android JUnit extensions provide component-specific test case classes.
CS378 - Mobile Computing Intents.
Automated GUI testing How to test an interactive application automatically?
Unit testing Unit testing TDD with JUnit. Unit Testing Unit testing with JUnit 2 Testing concepts Unit testing Testing tools JUnit Practical use of tools.
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Android - Broadcast Receivers
JUnit test and Project 3 simulation. 2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT.
Android Development Environment Environment/tools Windows Eclipse IDE for Java Developers (v3.5 Galileo) Java Platform (JDK 6 Update 18) Android.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
JUnit Dwight Deugo Nesa Matic
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
JUnit Dwight Deugo Nesa Matic
JUnit Don Braffitt Updated: 10-Jun-2011.
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
1 CSC 216 Lecture 3. 2 Unit Testing  The most basic kind of testing is called unit testing  Why is it called “unit” testing?  When should tests be.
JUnit A Unit Testing Framework for Java. The Objective Introduce JUnit as a tool for Unit Testing Provide information on how to: Install it Build a test.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
Test a Little, Code a Little Colin Sharples IBM Global Services New Zealand Colin Sharples IBM Global Services New Zealand.
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
JUnit Testing Why we do this and how we can get better.
PHPUnit Julia Bondar IAPM23. Agenda What is PHPUnit How to write an automated test Writing and running tests with PHPUnit Advantages and disadvantages.
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
Automated Testing with PHPUnit. How do you know your code works?
Guide To Develop Mobile Apps With Titanium. Agenda Overview Installation of Platform SDKs Pros of Appcelerator Titanium Cons of Appcelerator Titanium.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Is it really possible to test my app? By Paweł Suszek
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Test-Driven Development and Android
Activities and Intents
Mobile Device Development
CMPE419 Mobile Application Development
Android – tESTING L. Grewe.
Introduction to JUnit IT323 – Software Engineering II
The Most Popular Android UI Automation Testing Tool Andrii Voitenko
Joel Adams and Jeremy Frens Calvin College
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
CMPE419 Mobile Application Development
Presentation transcript:

ANDROID – TESTING L. Grewe

With the AndroidStudio IDE

Setup Configurations  STEP 1:Run->Edit Configurations  STEP 2: Hit + in Config window and add Android Tests

Setup continued  Step 3: Now configure Testing configuration to point to the module of your app  select“All in Module” and Android Studio will automatically find any test inside your whole Module! You can also get more specific and select “Class” or even “Method” option to narrow the scope of your testing down further. All test methods MUST start with the “test-” prefix or Android Studio will not detect them as tests and you will get all kinds of weird errors and nothing will work.

Setup finished  Step 4: after saving config in Step 3 you can see it is an option for running (now we have the app itself and the testing classes)  NEXT how do we make the testing code

When you create Project –you have testing directory preset up.  Look at this example for a simple HelloWorld app  Can also create test directory under the package (here com.example.lynne.hello then would be called come.example.lynne.hello.test )

Writing Test classes - Based on JUnit  use plain JUnit to test a class that doesn't call the Android API,  JUnit TestCase class to do unit testing on a class that doesn't call Android APIs.TestCase  Use Android's JUnit extensions to test Android components.  Android JUnit extensions provide component-specific test case classes.  provide helper methods for creating mock objects and methods that help you control the lifecycle of a component.

Testing PLO (plain old java object)  Plain Old Java Objects  (i.e. independent of frameworks like Android or J2EE)  Test using assertX = assertTrue, assertEquals to see if value is true or euqals some value. import junit.framework.TestCase; import com.android.lab4.Joke; public class JokeTest extends TestCase { public void testJoke() { Joke joke = new Joke(); assertTrue("m_strJoke should be initialized to \"\".", joke.getJoke().equals("")); assertTrue("m_strAuthorName should be initialized to \"\".", joke.getAuthor().equals("")); assertEquals("m_nRating should be initialized to Joke.UNRATED.", Joke.UNRATED, joke.getRating()); }

Testing using android.test  Here creating classes (extending) from existing classes in android.test

AndroidTestCase class  voidassertActivityRequiresPermissionassertActivityRequiresPermission(String packageName, String className, String permissi on)Asserts that launching a given activity is protected by a particular permission by attempting to start the activity and validating that a SecurityException is thrown that mentions the permission in its error message.String SecurityException voidassertReadingContentUriRequiresPermissionassertReadingContentUriRequiresPermission(Uri uri, String permission)Asserts that reading from the content uri requires a particular permission by querying the uri and ensuring a SecurityException is thrown mentioning the particular permission.UriStringSecurityException voidassertWritingContentUriRequiresPermissionassertWritingContentUriRequiresPermission(Uri uri, String permission)Asserts that writing to the content uri requires a particular permission by inserting into the uri and ensuring a SecurityException is thrown mentioning the particular permission.UriStringSecurityException ContextgetContextgetContext() voidsetContextsetContext(Context context)Context voidtestAndroidTestCaseSetupProperlytestAndroidTestCaseSetupProperly() voidsetup() and teardown() extends TestCase and Assert, which you can use to test Android- dependent objects. AndroidTestCase offers Android-specific setup, teardown, and helper methods. testing permissions

ApplicationTest class  ApplicationTestCase ApplicationTestCase  test case class to test the setup and teardown of Application objects.Application  can be useful in verifying that the element in the manifest file is correctly set up. Note, however, that this test case does not allow you to control testing of the components within your application package.

Many other classes in android.test  InstrumentationClass  ActivityUnitTestCase  ActivityInstrumentaitonTestCase*  LOOK AT METHODS……read Android guide to testing online  oid.html oid.html  Testing Activities ---read this

What would some real test code look like… suppose you have Activity with Spinner public class myActivityTest extends ActivityInstrumentationTestCase2 {ActivityInstrumentationTestCase2 public void test() throws Exception { // Start the main activity of the application under test—gets this from parent class mActivity = getActivity(); // Get a handle to the Activity object's main UI widget, a Spinner mSpinner = (Spinner)mActivity.findViewById(com.android.example.spinner.R.id.Spinner01); // Set the Spinner to a known position mActivity.setSpinnerPosition(TEST_STATE_DESTROY_POSITION); // Stop the activity - The onDestroy() method should save the state of the Spinner mActivity.finish(); // Re-start the Activity - the onResume() method should restore the state of the Spinner mActivity = getActivity(); // Get the Spinner's current position int currentPosition = mActivity.getSpinnerPosition(); // Assert that the current position is the same as the starting position assertEquals(TEST_STATE_DESTROY_POSITION, currentPosition); How does this connect to the actual Activity class you want to test THROUGH the constructor public ActivityInstrumentationTestCase2 (Class activityClass)Class where the parameter is the class you want to test All test methods MUST start with the “test-” prefix or Android Studio will not detect them as tests and you will get all kinds of weird errors and nothing will work.

Simply run the config you setup earlier (see start of talk) Running tests

More on your own  Only touched the tip  Other apis part of android.test  Testing UIs  Testing Services  Testing ContentProviders  See

With the Eclipse IDE

Create a “Test Project”  File->New->Android Test Project (find it)  Give a Name  Select Target –the Android Project you are going to test

Create new Junit Test class  In src/package “New->Junit Test Case

Testing PLO (plain old java object)  Plain Old Java Objects  (i.e. independent of frameworks like Android or J2EE)  Test using assertX = assertTrue, assertEquals to see if value is true or euqals some value. import junit.framework.TestCase; import com.android.lab4.Joke; public class JokeTest extends TestCase { public void testJoke() { Joke joke = new Joke(); assertTrue("m_strJoke should be initialized to \"\".", joke.getJoke().equals("")); assertTrue("m_strAuthorName should be initialized to \"\".", joke.getAuthor().equals("")); assertEquals("m_nRating should be initialized to Joke.UNRATED.", Joke.UNRATED, joke.getRating()); }

Running the Junit tests  Right click and select Run As -> Android JUnit Test

Test Project Manifest File  Note targets the project’s package you want to test  Note places it in same packagename.test <manifest xmlns:android=" package="com.example.helloworld.test" android:versionCode="1" android:versionName="1.0" > <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.helloworld" /> <application >

Naming your Test JUnit classes  If testing a class called MainActivity call you Junit class MainActivity_Test or MainActivity_TestCase