1 / 30

Unit Test

Unit Test. 2009-12041 Kim TaeHun. JUnit test. Writing Java Codes Add JUnit library in project (Using ‘preference’ Menu ). J U nit test(Cntd). 3. Package – ‘New’ – ‘ Junit Test Case’. J U nit test(Cntd). 4 . Name, Class and Method Setting. J U nit test(Cntd).

ken
Télécharger la présentation

Unit Test

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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 - http://junit.org/javadoc/latest/org/junit/Assert.html Annotation - https://github.com/junit-team/junit/wiki (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 : http://easymock.org/

  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(http://developer.android.com/reference/android/test/mock/MockPackageManager.html) OR Using EasyMock(http://ncona.com/2013/11/writing-unit-test-for-android-with-easymock/)

  17. C/C++ Unit Test CppUnit http://nyolong.egloos.com/2250020 http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html Google Test https://code.google.com/p/googletest/wiki/Primer http://salkuma.wordpress.com/2014/02/17/google-test-%EC%82%AC%EC%9A%A9%EB%B2%95/ http://stinkfist.egloos.com/2262578 https://code.google.com/p/googletest/wiki/AdvancedGuide https://code.google.com/p/googlemock/wiki/CookBook#Teaching_Google_Mock_How_to_Print_Your_Values http://www.slideshare.net/zone0000/c-7522148 http://lancerme.tistory.com/19

  18. C/C++ Unit Test(Cntd) UnitTest++ http://unittest-cpp.sourceforge.net/ http://unittest-cpp.sourceforge.net/money_tutorial/ http://unittest-cpp.sourceforge.net/UnitTest++.html http://ospace.tistory.com/203 TUT http://mrzechonek.github.io/tut-framework/

  19. C/C++ Unit Test(Cntd) CUnit http://cunit.sourceforge.net/index.html http://galaxyra.linuxstudy.pe.kr/galaxyra/14 http://cunit.sourceforge.net/doc/index.html

  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(https://code.google.com/p/googlemock/wiki/ForDummies) Can be used with Any Testing Framework

  30. References Junit http://using.tistory.com/entry/JUnit-%ED%85%8C%EC%8A%A4%ED%8A%B8-%ED%95%98%EA%B8%B0 https://github.com/junit-team/junit/wiki http://lyb1495.tistory.com/73 http://easymock.org/EasyMock3_2_Documentation.html Android App Unit Test http://www.imaso.co.kr/?doc=bbs/gnuboard.php&bo_table=article&wr_id=39290 http://developer.android.com/tools/testing/testing_android.html http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html http://developer.android.com/tools/testing/activity_testing.html https://developer.android.com/training/activity-testing/activity-unit-testing.html https://developer.android.com/training/testing.html Google Test http://ra2kstar.tistory.com/138

More Related