unit test n.
Skip this Video
Loading SlideShow in 5 Seconds..
Unit Test PowerPoint Presentation

Unit Test

226 Vues Download Presentation
Télécharger la présentation

Unit Test

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Unit Test 2009-12041 Kim TaeHun

  2. JUnit test • Writing Java Codes • Add JUnit library in project (Using ‘preference’ Menu)

  3. JUnit test(Cntd) 3. Package – ‘New’ – ‘Junit Test Case’

  4. JUnit test(Cntd) 4. Name, Class and Method Setting

  5. JUnit test(Cntd) 5. Set Assert Function Assert API - Annotation - (ex : @Test(timeout=5000), @Test(expected=RuntimeException.class), @Test(timeout=5000), @Ignore(value=”ignore”) @Before, @After)

  6. JUnit test(Cntd) Using EasyMock Using when external class isn’t completed. Interface of incomplete class is need. Download and add library :

  7. JUnit test(Cntd)

  8. Android App Unit Test Android test suites are based on JUnit. You can use plain JUnit to test a class that doesn't call the Android API, or Android's JUnit extensions to test Android components.

  9. Android App Unit Test(Cntd) 1. New – Project – Android Test Project

  10. Android App Unit Test(Cntd) 2. Set Project Name, Target

  11. Android App Unit Test(Cntd) 3. New – JunitTestcase Set Name, Superclass, Class Under Test

  12. Android App Unit Test(Cntd) Superclass for Activity ActivityInstrumentationTestCase2 The ActivityInstrumentationTestCase2 test case class is designed to do functional testing of one or more Activities in an application, using a normal system infrastructure. It runs the Activities in a normal instance of the application under test, using a standard system Context. It allows you to send mock Intents to the activity under test, so you can use it to test an activity that responds to multiple types of intents, or an activity that expects a certain type of data in the intent, or both. Notice, though, that it does not allow mock Contexts or Applications, so you can not isolate the test from the rest of a production system. ActivityUnitTestCase The ActivityUnitTestCase test case class tests a single activity in isolation. Before you start the activity, you can inject a mock Context or Application, or both. You use it to run activity tests in isolation, and to do unit testing of methods that do not interact with Android. You can not send mock Intents to the activity under test, although you can call Activity.startActivity(Intent) and then look at arguments that were received. SingleLaunchActivityTestCase The SingleLaunchActivityTestCase class is a convenience class for testing a single activity in an environment that doesn't change from test to test. It invokes setUp() and tearDown() only once, instead of once per method call. It does not allow you to inject any mock objects. This test case is useful for testing an activity that runs in a mode other than standard. It ensures that the test fixture is not reset between tests. You can then test that the activity handles multiple calls correctly.

  13. Android App Unit Test(Cntd) Superclass for Service ServiceTestCase extends the JUnitTestCase class with with methods for testing application permissions and for controlling the application and Service under test. It also provides mock application and Context objects that isolate your test from the rest of the system. ServiceTestCase defers initialization of the test environment until you call ServiceTestCase.startService() or ServiceTestCase.bindService(). This allows you to set up your test environment, particularly your mock objects, before the Service is started. Notice that the parameters to ServiceTestCase.bindService()are different from those for Service.bindService(). For the ServiceTestCase version, you only provide an Intent. Instead of returning a boolean, ServiceTestCase.bindService() returns an object that subclasses IBinder. The setUp() method for ServiceTestCase is called before each test. It sets up the test fixture by making a copy of the current system Context before any test methods touch it. You can retrieve this Context by calling getSystemContext(). If you override this method, you must call super.setUp() as the first statement in the override. The methods setApplication() and setContext(Context) setContext()} allow you to set a mock Context or mock Application (or both) for the Service, before you start it. These mock objects are described in Mock object classes. By default, ServiceTestCase runs the test method testAndroidTestCaseSetupProperly(), which asserts that the base test case class successfully set up a Context before running.

  14. Android App Unit Test(Cntd) 4. Write Testcase and Run As – Android Junit Test

  15. Android App Unit Test(Cntd)

  16. Android App Unit Test(Cntd) Moking Using android.test.mock.MockPackageManager( OR Using EasyMock(

  17. C/C++ Unit Test CppUnit Google Test

  18. C/C++ Unit Test(Cntd) UnitTest++ TUT

  19. C/C++ Unit Test(Cntd) CUnit

  20. Google Test 1. Download gtest and compile

  21. Google Test(Cntd) 2. Download eclipse and write c++ code to test

  22. Google Test(Cntd) 3. Make Project for Test

  23. Google Test(Cntd) 4. Set include, library, miscellaneous

  24. Google Test(Cntd) 4. Set include, library, miscellaneous

  25. Google Test(Cntd) 4. Set include, library, miscellaneous

  26. Google Test(Cntd) 5. Write Test Code

  27. Google Test(Cntd) 6. Compile and Run

  28. Google Test(Cntd) 6. Compile and Run

  29. GoogleMock Mock Framework for C++ Unit Test : GoogleMock( Can be used with Any Testing Framework

  30. References Junit Android App Unit Test Google Test