NFP121 1 NFP121, Cnam/Paris JUnit tests pour Android Notes sur l’usage de JUnit3 sous Android Cnam Paris jean-michel Douin, douin au cnam point fr version en cours Le lecteur intéressé par un cours sur les tests pourra se référer à celui de l’université de Trente « Software Analysis and Testing » http://selab.fbk.eu/swat/program.ml?lang=en
44
Embed
NFP121, Cnam/Paris JUnittests pour Androidjfod.cnam.fr/seja/supports_pdf/cours_Android_Tests_Unit... · 2012. 10. 12. · NFP121 1 NFP121,Cnam/Paris JUnittests pour Android Notes
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
NFP1211
NFP121, Cnam/ParisJUnit tests pour Android
Notes sur l’usage de JUnit3 sous Android
Cnam Parisjean-michel Douin, douin au cnam point fr
version en cours
Le lecteur intéressé par un cours sur les tests pourra se référer à celui de l’université de Trente « Software Analysis and Testing » http://selab.fbk.eu/swat/program.ml?lang=en
NFP1212
Avertissement
• Ce support a comme pré-requis :– La connaissance de junit3– Ou la lecture de ce support
• http://jfod.cnam.fr/NFP121/supports/junit3_tests.pd f
NFP1213
Sommaire du « triptyque »
1. Présentation de JUnit, les bases
2. Android et les tests unitaires
3. Assertions et programmation par contrats
NFP1214
Sommaire : Les 3 fichiers
Junit3http://jfod.cnam.fr/NFP121/supports/junit3_tests.pd f
http://jfod.cnam.fr/NFP121/supports/junit3_tests.ja r
• http://developer.android.com/resources/tutorials/testing/helloandroid_test.html• http://developer.android.com/guide/topics/testing/index.html• Test Driven Development and Android : http://www.bhecker.com/ap-tdd.ppt
• set path=D:\android-sdk-windows\platform-tools;%PATH%• adb shell am instrument -w cnam.hello.test/android.test.InstrumentationTestRunner•
• cnam.hello.test.HelloAndroidTest:.• Failure in testText:• junit.framework.ComparisonFailure: expected:<... World, HelloActivity!> but was:<..., Android>• at cnam.hello.test.HelloAndroidTest.testText(HelloAndroidTest.java:29)• at java.lang.reflect.Method.invokeNative(Native Method)• at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)• at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)• at
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)• at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)• at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)• at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)• at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
• Test results for InstrumentationTestRunner=..F• Time: 0.667
• tp.pile.test.ihm.PileTestIHM:........• tp.pile.test.persistance.TestPersistance:....• tp.pile.tests.modele.Pile2Test:...............• tp.pile.tests.modele.Pile2_RepOk_AffTest:..• tp.pile.tests.modele.Pile4Test:...............• tp.pile.tests.modele.PileModeleTest:...• Test results for
• Pas concluant: génération d’un fichier coverage.ecavec 37 octets
NFP12137
Stress
• Random stress testing – From http://d.android.com/guide/developing/tools/mo nkey.html– When the Monkey runs, it generates events and sends them to the
system. It also watches the system under test and looks for three conditions, which it treats specially:
• If you have constrained the Monkey to run in one or more specific packages, it watches for attempts to navigate to an y other packages, and blocks them.
• If your application crashes or receives any sort of unhandled exception, the Monkey will stop and report the erro r.
• If your application generates an application not responding error, the Monkey will stop and report the error.
adb shell monkey -p cnam.hello -v 500
NFP12138
Stress d’une Activity
NFP12139
Emma et Android
• Emma et Android– http://stackoverflow.com/questions/2762665/how-to-use-emma-
code-coverage-in-android
NFP12140
NFP12141
A voir de près
robotiumIt's like Selenium, but for Android™
http://code.google.com/p/robotium/
NFP12142
À terminer
– public class FunctionalTest extends – ActivityInstrumentationTestCase2<AdvancedJokeList> {– public FunctionalTest() { super ("edu.calpoly.android.lab2", AdvancedJokeList.class);}– protected void setUp() throws Exception { super.setUp(); }– public void testAddJoke() {– ArrayList<Joke> m_arrJokeList = null;– m_arrJokeList = this.retrieveHiddenMember ("m_arrJokeList",– m_arrJokeList,getActivity());– assertEquals("Should be 3 default jokes",m_arrJokeList.size(),3);– getActivity().runOnUiThread (new Runnable() {– public void run () {– AdvancedJokeList theActivity = (AdvancedJokeList)getActivity();– EditText et = (EditText)theActivity.– findViewById (edu.calpoly.android.lab2.R.id.newJokeEditText);– Button bt = (Button)theActivity.– findViewById (edu.calpoly.android.lab2.R.id.addJokeButton);– et.setText ("This is a test joke");– bt.performClick ();– }});– getInstrumentation().waitForIdleSync(); // wait for the request to go through– assertEquals("Should be 4 jokes now",m_arrJokeList.size(),4);– assertEquals("Ensure the joke we added is really there",– m_arrJokeList.get(3).getJoke(),"This is a test joke");– }
NFP12143
NFP12144
AndroidTestCase extends junit.framework.TestCase
• Extrait de Android Application Testing Guide, Cf. biblio