SlideShare a Scribd company logo
1 of 30
Unit Test
2009-12041 Kim TaeHun
JUnit test
1. Writing Java Codes
2. 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/
JUnit test(Cntd)
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 – Junit Testcase
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 JUnit TestCase 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)
Android App Unit Test(Cntd)
Moking
Using android.test.mock.MockPackageManager
(http://developer.android.com/reference/android/test/mock/MockPac
kageManager.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/ForDum
mies)
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

More Related Content

What's hot

TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010Stefano Paluello
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit TestingMike Lively
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Jacinto Limjap
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010kgayda
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesNarendra Pathai
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Thomas Weller
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.xdjberg96
 

What's hot (20)

JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Junit
JunitJunit
Junit
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Junit
JunitJunit
Junit
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Unit test
Unit testUnit test
Unit test
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
J Unit
J UnitJ Unit
J Unit
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.x
 

Similar to Unit test

J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAhmed Ehab AbdulAziz
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentationSanjib Dhar
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PBAbhishek Yadav
 
Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013Svetlin Nakov
 
Unit testing by Svetlin Nakov
Unit testing by Svetlin NakovUnit testing by Svetlin Nakov
Unit testing by Svetlin Nakovit-tour
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactusHimanshu
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightOpenDaylight
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxKnoldus Inc.
 

Similar to Unit test (20)

Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Junit
JunitJunit
Junit
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013
 
Unit testing by Svetlin Nakov
Unit testing by Svetlin NakovUnit testing by Svetlin Nakov
Unit testing by Svetlin Nakov
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactus
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
ikp321-04
ikp321-04ikp321-04
ikp321-04
 
Unit testing basic
Unit testing basicUnit testing basic
Unit testing basic
 
3 j unit
3 j unit3 j unit
3 j unit
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptx
 

Recently uploaded

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...Health
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 

Recently uploaded (20)

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 

Unit test

  • 2. JUnit test 1. Writing Java Codes 2. 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/
  • 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 – Junit Testcase 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 JUnit TestCase 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/MockPac kageManager.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
  • 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
  • 29. GoogleMock Mock Framework for C++ Unit Test : GoogleMock (https://code.google.com/p/googlemock/wiki/ForDum mies) 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