310 likes | 1.48k Views
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).
E N D
Unit Test 2009-12041 Kim TaeHun
JUnit test • Writing Java Codes • Add JUnit library in project (Using ‘preference’ Menu)
JUnit test(Cntd) 3. Package – ‘New’ – ‘Junit Test Case’
JUnit test(Cntd) 4. Name, Class and Method Setting
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)
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/
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.
Android App Unit Test(Cntd) 1. New – Project – Android Test Project
Android App Unit Test(Cntd) 2. Set Project Name, Target
Android App Unit Test(Cntd) 3. New – JunitTestcase Set Name, Superclass, Class Under Test
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.
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.
Android App Unit Test(Cntd) 4. Write Testcase and Run As – Android Junit Test
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/)
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
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/
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
Google Test 1. Download gtest and compile
Google Test(Cntd) 2. Download eclipse and write c++ code to test
Google Test(Cntd) 3. Make Project for Test
Google Test(Cntd) 4. Set include, library, miscellaneous
Google Test(Cntd) 4. Set include, library, miscellaneous
Google Test(Cntd) 4. Set include, library, miscellaneous
Google Test(Cntd) 5. Write Test Code
Google Test(Cntd) 6. Compile and Run
Google Test(Cntd) 6. Compile and Run
GoogleMock Mock Framework for C++ Unit Test : GoogleMock(https://code.google.com/p/googlemock/wiki/ForDummies) Can be used with Any Testing Framework
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