Unit Testing Android Applications

Rody Middelkoop
Rody MiddelkoopLecturer @HAN University em Hogeschool van Arnhem en Nijmegen
Tests, Stubs, Mocks
 Effective Unittesting for
android
Goals of test automation
 Improve quality
 Understand the SUT
 Reduce the risk
 Easy to run
 Easy to write
 Easy to maintain
Subject
Under
Test
Principles in test automation
 Write the test first.
 Each test should be:
– Small and simple
– Independent to other test
– Repeatable
– Self-checking  Fully Automated
 First do “State verification”
and then “Behavior Verification”.
Which part can be automated?
System Under Test
 It may have Depended-on components
Image From: xunit Test Patterns, G. Meszaros
What are we talking about?
 Pattern: Test Double
 Also known as: Imposter
 Problem: How can we verify logic
independently when code it depends
on is unusable? How can we avoid
Slow Tests?
 Solution: We replace a component on
which the SUT depends with a "test-
specific equivalent."
WHAT?
Test Doubles:
 Dummy Object: Temporary Object that does not influence the SUT
 Test Stub: Hand coded object used for testing
 Test Spy: Verification occurs after the test method has been called
 Mock Object: Expectations configured before calling tests
 Fake Object: Typically, it implements the same functionality as the real
DOC but in a much simpler way, no expectation are configured.
Mock? Why?
 Mock - a simulated object that
mimics the behavior of a real
object in controlled ways.
Four phase testing
Image From: xunit Test Patterns, G. Meszaros
Test structure
Setup
Execute
Verify
Effective test automation
 After test generation by considering all
paths and the features and
organization specified, our test still
may have these bad smells:
– Slow Tests
– Test Code Duplication
– Obscure Tests
– Buggy Tests
Image SRC: www.dilbert.com
Mockito, how to drink it? framework basics
import static org.mockito.Mockito.*;
//mock creation
LinkedList mockedList = mock(LinkedList.class);
//using mock object
mockedList.add("one");
mockedList.clear();
//verification
verify(mockedList).add("one");
verify(mockedList).clear();
Stub - Mockito can
mock concrete
classes, not only
interfaces
Mockito, how to drink it? framework basics
 Return value thenReturn()
when(mock.someMethod("some
arg")).thenReturn("foo");
 Stubbing voids requires doReturn()
doReturn("bar").when(mock).foo();
What else to use
 PowerMock (private, final,static
methods)
 Jmockit (constructors and static
methods mocking)
 Hamcrest (library of matcher objects
(also known as constraints or
predicates) allowing 'match' rules to be
defined declaratively)
ANDROID UNIT TESTING
EXAMPLE: JUNIT + ROBOLECTRIC for Android
 Android unit testing is tricky:
– android.jar only contains mocked out .class
files which leads to
java.lang.RuntimeException: Stub!
 TIPS:
– Keep things simple by trying to make as many
services as possible not dependent on the
parts of the Android platform that are not
compatible with a conventional JVM.
– Robolectric to the rescue
Unit test depending on Android api
@RunWith(RobolectricTestRunner.class)
public class PopularRoutesAdapterTest {
private PopularRoutesAdapter adapter;
@Before
public void setUp() {
adapter = new PopularRoutesAdapter(
Robolectric.buildActivity(Activity.class).create().get();
}
@Test
public void testAddItem() {
assertEquals(0, adapter.getCount());
adapter.addItem(new Route("Arnhem"));
assertEquals(1, adapter.getCount());
}
Special test runner
coming with
Robolectric
Activity class is
mocked by
Robolectric
General rules to remember
 Mock it outside your code
 If you cannot test your code -> then probably
you should change it ;) cause its badly
written
 Test first
 Only one concrete class , mock the rest
 Only mock your neirest neighbour (Law of
Demeter -> dont talk with strangers)
 Think ;) and then write
Robo-WTF
Robolectric
 Has Java
implementations of
class files for most of
the Android API
 Enables true
unittesting, being not
dependent on any
network, hardware,
device or database
Roboguice
 Guice for Robolectric
 Dependency Injection
based in Google Guice
 Code bases DI instead
of XML (like in Spring)
Deckard
 Combination of
– Gradle / Maven
– Robolectric
– Junit
 Example adds
– Roboguice
– Mockito
DEMO
Developers Not Writing Tests
 Symptoms:
– No tests can be found when you ask to see the
• unit tests for a task,
• customer tests for a User Story,
– Lack of clarity about what a user story or task really means
 Impact:
– Lack of safety net
– Lack of focus
 Possible Causes:
– Hard to Test Code?
– Not enough time?
– Don’t have the skills?
– Have been told not to?
– Don’t see the value?
Robolectric for
unittesting
Espresso for
scenario-testing
Resources
 https://github.com/ddoa/dea-code-
examples/android-deckard-unittest/
 http://pages.cpsc.ucalgary.ca/~maurer/upload
s/SENG515615F2007/XUnitTestPattern.ppt
 http://code.google.com/p/mockito/
 https://docs.google.com/presentation/d/1J0W
iFJI9wSkc3UMsNXYv8ixX5orjkYzduwyOalzEk
jU/embed?hl=pl&size=l#slide=id.p5
1 de 24

Recomendados

Introduction to android testing por
Introduction to android testingIntroduction to android testing
Introduction to android testingDiego Torres Milano
22.1K visualizações197 slides
Unit Testing in Android por
Unit Testing in AndroidUnit Testing in Android
Unit Testing in AndroidShamsul Arafin Mahtab
133 visualizações23 slides
Integration test por
Integration testIntegration test
Integration testsadegh salehi
10.7K visualizações40 slides
Unit Testing por
Unit TestingUnit Testing
Unit TestingSergey Podolsky
2.1K visualizações116 slides
JUnit Presentation por
JUnit PresentationJUnit Presentation
JUnit Presentationpriya_trivedi
17.7K visualizações26 slides
Karate - powerful and simple framework for REST API automation testing por
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingRoman Liubun
5.4K visualizações20 slides

Mais conteúdo relacionado

Mais procurados

TestNG Framework por
TestNG Framework TestNG Framework
TestNG Framework Levon Apreyan
8.3K visualizações39 slides
API Testing With Katalon Studio por
API Testing With Katalon StudioAPI Testing With Katalon Studio
API Testing With Katalon StudioKnoldus Inc.
842 visualizações10 slides
Android testing por
Android testingAndroid testing
Android testingJinaTm
3.6K visualizações34 slides
Manual testing ppt por
Manual testing pptManual testing ppt
Manual testing pptSantosh Maranabasari
35.8K visualizações15 slides
Introduction to selenium por
Introduction to seleniumIntroduction to selenium
Introduction to seleniumArchana Krushnan
7.1K visualizações21 slides
Defect life cycle and Defect Status Life Cycle por
Defect life cycle and Defect Status Life CycleDefect life cycle and Defect Status Life Cycle
Defect life cycle and Defect Status Life Cyclepavansmiles
1.5K visualizações6 slides

Mais procurados(20)

TestNG Framework por Levon Apreyan
TestNG Framework TestNG Framework
TestNG Framework
Levon Apreyan8.3K visualizações
API Testing With Katalon Studio por Knoldus Inc.
API Testing With Katalon StudioAPI Testing With Katalon Studio
API Testing With Katalon Studio
Knoldus Inc.842 visualizações
Android testing por JinaTm
Android testingAndroid testing
Android testing
JinaTm3.6K visualizações
Manual testing ppt por Santosh Maranabasari
Manual testing pptManual testing ppt
Manual testing ppt
Santosh Maranabasari35.8K visualizações
Introduction to selenium por Archana Krushnan
Introduction to seleniumIntroduction to selenium
Introduction to selenium
Archana Krushnan7.1K visualizações
Defect life cycle and Defect Status Life Cycle por pavansmiles
Defect life cycle and Defect Status Life CycleDefect life cycle and Defect Status Life Cycle
Defect life cycle and Defect Status Life Cycle
pavansmiles1.5K visualizações
Coding standard por FAROOK Samath
Coding standardCoding standard
Coding standard
FAROOK Samath3.1K visualizações
Manual testing concepts course 1 por Raghu Kiran
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
Raghu Kiran14.9K visualizações
Code Quality por François Camus
Code QualityCode Quality
Code Quality
François Camus2.1K visualizações
Introduction to Automation Testing por Archana Krushnan
Introduction to Automation TestingIntroduction to Automation Testing
Introduction to Automation Testing
Archana Krushnan8.6K visualizações
Junit por FAROOK Samath
JunitJunit
Junit
FAROOK Samath6.9K visualizações
Software Testing - Defect/Bug Life Cycle - Complete Flow Chart of Defect States por eVideoTuition
Software Testing - Defect/Bug Life Cycle - Complete Flow Chart of Defect StatesSoftware Testing - Defect/Bug Life Cycle - Complete Flow Chart of Defect States
Software Testing - Defect/Bug Life Cycle - Complete Flow Chart of Defect States
eVideoTuition13.9K visualizações
Mobile Automation with Appium por Manoj Kumar Kumar
Mobile Automation with AppiumMobile Automation with Appium
Mobile Automation with Appium
Manoj Kumar Kumar2.8K visualizações
Java interfaces por jehan1987
Java interfacesJava interfaces
Java interfaces
jehan19872.9K visualizações
BDD with Cucumber por Knoldus Inc.
BDD with CucumberBDD with Cucumber
BDD with Cucumber
Knoldus Inc.15.8K visualizações
Test Driven Development (TDD) Preso 360|Flex 2010 por guest5639fa9
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9536 visualizações

Destaque

Testing for Android: When, Where, and How to Successfully Use Test Automation por
Testing for Android: When, Where, and How to Successfully Use Test AutomationTesting for Android: When, Where, and How to Successfully Use Test Automation
Testing for Android: When, Where, and How to Successfully Use Test AutomationTrent Peterson
1.1K visualizações40 slides
Android Performance Tips & Tricks por
Android Performance Tips & TricksAndroid Performance Tips & Tricks
Android Performance Tips & TricksSergii Zhuk
1.3K visualizações25 slides
Introduction to android testing - oscon 2012 por
Introduction to android testing - oscon 2012Introduction to android testing - oscon 2012
Introduction to android testing - oscon 2012OSCON Byrum
10.6K visualizações161 slides
Testing Android Application, Droidcon Torino por
Testing Android Application, Droidcon TorinoTesting Android Application, Droidcon Torino
Testing Android Application, Droidcon TorinoPietro Alberto Rossi
575 visualizações14 slides
Android Testing: An Overview por
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An OverviewSmartLogic
3.4K visualizações37 slides
Testing Android applications with Maveryx por
Testing Android applications with MaveryxTesting Android applications with Maveryx
Testing Android applications with MaveryxMaveryx
949 visualizações48 slides

Destaque(20)

Testing for Android: When, Where, and How to Successfully Use Test Automation por Trent Peterson
Testing for Android: When, Where, and How to Successfully Use Test AutomationTesting for Android: When, Where, and How to Successfully Use Test Automation
Testing for Android: When, Where, and How to Successfully Use Test Automation
Trent Peterson1.1K visualizações
Android Performance Tips & Tricks por Sergii Zhuk
Android Performance Tips & TricksAndroid Performance Tips & Tricks
Android Performance Tips & Tricks
Sergii Zhuk1.3K visualizações
Introduction to android testing - oscon 2012 por OSCON Byrum
Introduction to android testing - oscon 2012Introduction to android testing - oscon 2012
Introduction to android testing - oscon 2012
OSCON Byrum10.6K visualizações
Testing Android Application, Droidcon Torino por Pietro Alberto Rossi
Testing Android Application, Droidcon TorinoTesting Android Application, Droidcon Torino
Testing Android Application, Droidcon Torino
Pietro Alberto Rossi575 visualizações
Android Testing: An Overview por SmartLogic
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An Overview
SmartLogic3.4K visualizações
Testing Android applications with Maveryx por Maveryx
Testing Android applications with MaveryxTesting Android applications with Maveryx
Testing Android applications with Maveryx
Maveryx949 visualizações
Android Building, Testing and reversing por Enrique López Mañas
Android Building, Testing and reversingAndroid Building, Testing and reversing
Android Building, Testing and reversing
Enrique López Mañas1.6K visualizações
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016 por Danny Preussler
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
Danny Preussler947 visualizações
Inside Android Testing por Fernando Cejas
Inside Android TestingInside Android Testing
Inside Android Testing
Fernando Cejas1.7K visualizações
Android Testing, Why So Hard?! por Annyce Davis
Android Testing, Why So Hard?!Android Testing, Why So Hard?!
Android Testing, Why So Hard?!
Annyce Davis2K visualizações
Testing Android por Marc Chung
Testing AndroidTesting Android
Testing Android
Marc Chung1.8K visualizações
Testing With Open Source por Matthias Käppler
Testing With Open SourceTesting With Open Source
Testing With Open Source
Matthias Käppler686 visualizações
Unit testing in android por Li-Wei Cheng
Unit testing in androidUnit testing in android
Unit testing in android
Li-Wei Cheng2.6K visualizações
Unit testing on Android (Droidcon Dubai 2015) por Danny Preussler
Unit testing on Android (Droidcon Dubai 2015)Unit testing on Android (Droidcon Dubai 2015)
Unit testing on Android (Droidcon Dubai 2015)
Danny Preussler1.6K visualizações
Unit testing and Android por Tomáš Kypta
Unit testing and AndroidUnit testing and Android
Unit testing and Android
Tomáš Kypta1.9K visualizações
Mobile Performance Testing - Best Practices por Eran Kinsbrunner
Mobile Performance Testing - Best PracticesMobile Performance Testing - Best Practices
Mobile Performance Testing - Best Practices
Eran Kinsbrunner3.1K visualizações
Rapid Android Application Security Testing por Nutan Kumar Panda
Rapid Android Application Security TestingRapid Android Application Security Testing
Rapid Android Application Security Testing
Nutan Kumar Panda1.1K visualizações
Oh so you test? - A guide to testing on Android from Unit to Mutation por Paul Blundell
Oh so you test? - A guide to testing on Android from Unit to MutationOh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to Mutation
Paul Blundell5.6K visualizações
Testing on Android por Diego Torres Milano
Testing on AndroidTesting on Android
Testing on Android
Diego Torres Milano11.9K visualizações

Similar a Unit Testing Android Applications

Stopping the Rot - Putting Legacy C++ Under Test por
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
2.9K visualizações56 slides
Embrace Unit Testing por
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testingalessiopace
4K visualizações47 slides
Testing w-mocks por
Testing w-mocksTesting w-mocks
Testing w-mocksMacon Pegram
1.4K visualizações37 slides
Xp Day 080506 Unit Tests And Mocks por
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocksguillaumecarre
846 visualizações20 slides
Unit testing basic por
Unit testing basicUnit testing basic
Unit testing basicYuri Anischenko
2K visualizações26 slides
EasyMock for Java por
EasyMock for JavaEasyMock for Java
EasyMock for JavaDeepak Singhvi
5.4K visualizações38 slides

Similar a Unit Testing Android Applications(20)

Stopping the Rot - Putting Legacy C++ Under Test por Seb Rose
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose2.9K visualizações
Embrace Unit Testing por alessiopace
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
alessiopace4K visualizações
Testing w-mocks por Macon Pegram
Testing w-mocksTesting w-mocks
Testing w-mocks
Macon Pegram1.4K visualizações
Xp Day 080506 Unit Tests And Mocks por guillaumecarre
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
guillaumecarre846 visualizações
Unit testing basic por Yuri Anischenko
Unit testing basicUnit testing basic
Unit testing basic
Yuri Anischenko2K visualizações
EasyMock for Java por Deepak Singhvi
EasyMock for JavaEasyMock for Java
EasyMock for Java
Deepak Singhvi5.4K visualizações
Integration and Unit Testing in Java using Test Doubles like mocks and stubs por Rody Middelkoop
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Rody Middelkoop591 visualizações
Devday2016 real unittestingwithmockframework-phatvu por Phat VU
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvu
Phat VU449 visualizações
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S... por DevDay.org
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
DevDay.org618 visualizações
Mocking with Mockito por Paul Churchward
Mocking with MockitoMocking with Mockito
Mocking with Mockito
Paul Churchward388 visualizações
Google mock training por Thierry Gayet
Google mock trainingGoogle mock training
Google mock training
Thierry Gayet1.1K visualizações
Software Engineering - RS3 por Atakan Aral
Software Engineering - RS3Software Engineering - RS3
Software Engineering - RS3
Atakan Aral558 visualizações
Dependency Injection in .NET applications por Babak Naffas
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applications
Babak Naffas768 visualizações
Grails unit testing por pleeps
Grails unit testingGrails unit testing
Grails unit testing
pleeps4.1K visualizações
Integration testing por Tsegabrehan Am
Integration testingIntegration testing
Integration testing
Tsegabrehan Am16 visualizações
Win at life with unit testing por markstory
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
markstory4.6K visualizações
How and what to unit test por Eugenio Lentini
How and what to unit testHow and what to unit test
How and what to unit test
Eugenio Lentini1.4K visualizações
OpenDaylight Developer Experience 2.0 por Michael Vorburger
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
Michael Vorburger985 visualizações
Unit Testing Full@ por Alex Borsuk
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk220 visualizações

Mais de Rody Middelkoop

An agile mindset in education por
An agile mindset in education An agile mindset in education
An agile mindset in education Rody Middelkoop
443 visualizações36 slides
Themalunch scrum por
Themalunch scrumThemalunch scrum
Themalunch scrumRody Middelkoop
238 visualizações29 slides
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak por
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpakEduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpakRody Middelkoop
1.3K visualizações40 slides
Pecha Kucha eduScrum Agile Education por
Pecha Kucha eduScrum Agile EducationPecha Kucha eduScrum Agile Education
Pecha Kucha eduScrum Agile EducationRody Middelkoop
1.6K visualizações20 slides
Software Process Models por
Software Process ModelsSoftware Process Models
Software Process ModelsRody Middelkoop
1.3K visualizações53 slides
Softwarekwaliteit in een ontwikkelstraat por
Softwarekwaliteit in een ontwikkelstraatSoftwarekwaliteit in een ontwikkelstraat
Softwarekwaliteit in een ontwikkelstraatRody Middelkoop
1.8K visualizações41 slides

Mais de Rody Middelkoop(18)

An agile mindset in education por Rody Middelkoop
An agile mindset in education An agile mindset in education
An agile mindset in education
Rody Middelkoop443 visualizações
Themalunch scrum por Rody Middelkoop
Themalunch scrumThemalunch scrum
Themalunch scrum
Rody Middelkoop238 visualizações
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak por Rody Middelkoop
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpakEduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak
Rody Middelkoop1.3K visualizações
Pecha Kucha eduScrum Agile Education por Rody Middelkoop
Pecha Kucha eduScrum Agile EducationPecha Kucha eduScrum Agile Education
Pecha Kucha eduScrum Agile Education
Rody Middelkoop1.6K visualizações
Software Process Models por Rody Middelkoop
Software Process ModelsSoftware Process Models
Software Process Models
Rody Middelkoop1.3K visualizações
Softwarekwaliteit in een ontwikkelstraat por Rody Middelkoop
Softwarekwaliteit in een ontwikkelstraatSoftwarekwaliteit in een ontwikkelstraat
Softwarekwaliteit in een ontwikkelstraat
Rody Middelkoop1.8K visualizações
JavaScript on the server - Node.js por Rody Middelkoop
JavaScript on the server - Node.jsJavaScript on the server - Node.js
JavaScript on the server - Node.js
Rody Middelkoop4.6K visualizações
DDOA = Software Craftmanship por Rody Middelkoop
DDOA = Software CraftmanshipDDOA = Software Craftmanship
DDOA = Software Craftmanship
Rody Middelkoop748 visualizações
Back to the Future: Onderwijs van 1991 tot 2031 por Rody Middelkoop
Back to the Future: Onderwijs van 1991 tot 2031Back to the Future: Onderwijs van 1991 tot 2031
Back to the Future: Onderwijs van 1991 tot 2031
Rody Middelkoop375 visualizações
Scrum implemented in an educational context por Rody Middelkoop
Scrum implemented in an educational contextScrum implemented in an educational context
Scrum implemented in an educational context
Rody Middelkoop2.1K visualizações
Ajax And JSON por Rody Middelkoop
Ajax And JSONAjax And JSON
Ajax And JSON
Rody Middelkoop1.1K visualizações
OO JavaScript por Rody Middelkoop
OO JavaScriptOO JavaScript
OO JavaScript
Rody Middelkoop951 visualizações
Pragmatic Model Driven Development In Java Using Smart Use Cases por Rody Middelkoop
Pragmatic Model Driven Development In Java Using Smart Use CasesPragmatic Model Driven Development In Java Using Smart Use Cases
Pragmatic Model Driven Development In Java Using Smart Use Cases
Rody Middelkoop855 visualizações
Scrum in informaticaonderwijs por Rody Middelkoop
Scrum in informaticaonderwijsScrum in informaticaonderwijs
Scrum in informaticaonderwijs
Rody Middelkoop758 visualizações
Saas: Software AND Service por Rody Middelkoop
Saas: Software AND ServiceSaas: Software AND Service
Saas: Software AND Service
Rody Middelkoop512 visualizações
Service Analysis And Design por Rody Middelkoop
Service Analysis And DesignService Analysis And Design
Service Analysis And Design
Rody Middelkoop3.6K visualizações
ORM JPA por Rody Middelkoop
ORM JPAORM JPA
ORM JPA
Rody Middelkoop2.8K visualizações
Contract First Modeling Services Using Uml por Rody Middelkoop
Contract First Modeling Services Using UmlContract First Modeling Services Using Uml
Contract First Modeling Services Using Uml
Rody Middelkoop1.2K visualizações

Último

DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... por
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
14 visualizações23 slides
Short_Story_PPT.pdf por
Short_Story_PPT.pdfShort_Story_PPT.pdf
Short_Story_PPT.pdfutkarshsatishkumarsh
5 visualizações16 slides
Headless JS UG Presentation.pptx por
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptxJack Spektor
7 visualizações24 slides
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... por
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...Deltares
6 visualizações15 slides
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... por
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...Deltares
11 visualizações32 slides
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... por
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...Deltares
9 visualizações24 slides

Último(20)

DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... por Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares14 visualizações
Headless JS UG Presentation.pptx por Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 visualizações
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... por Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 visualizações
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... por Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares11 visualizações
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... por Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 visualizações
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action por Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok5 visualizações
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx por animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm14 visualizações
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... por Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 visualizações
Agile 101 por John Valentino
Agile 101Agile 101
Agile 101
John Valentino7 visualizações
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs por Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 visualizações
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... por Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller37 visualizações
Fleet Management Software in India por Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 visualizações
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... por Deltares
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
Deltares6 visualizações
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... por Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 visualizações
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... por sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik5 visualizações
Unleash The Monkeys por Jacob Duijzer
Unleash The MonkeysUnleash The Monkeys
Unleash The Monkeys
Jacob Duijzer7 visualizações
Advanced API Mocking Techniques por Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 visualizações
SAP FOR TYRE INDUSTRY.pdf por Virendra Rai, PMP
SAP FOR TYRE INDUSTRY.pdfSAP FOR TYRE INDUSTRY.pdf
SAP FOR TYRE INDUSTRY.pdf
Virendra Rai, PMP24 visualizações
Sprint 226 por ManageIQ
Sprint 226Sprint 226
Sprint 226
ManageIQ5 visualizações

Unit Testing Android Applications

  • 1. Tests, Stubs, Mocks  Effective Unittesting for android
  • 2. Goals of test automation  Improve quality  Understand the SUT  Reduce the risk  Easy to run  Easy to write  Easy to maintain Subject Under Test
  • 3. Principles in test automation  Write the test first.  Each test should be: – Small and simple – Independent to other test – Repeatable – Self-checking  Fully Automated  First do “State verification” and then “Behavior Verification”.
  • 4. Which part can be automated?
  • 5. System Under Test  It may have Depended-on components Image From: xunit Test Patterns, G. Meszaros
  • 6. What are we talking about?  Pattern: Test Double  Also known as: Imposter  Problem: How can we verify logic independently when code it depends on is unusable? How can we avoid Slow Tests?  Solution: We replace a component on which the SUT depends with a "test- specific equivalent."
  • 7. WHAT? Test Doubles:  Dummy Object: Temporary Object that does not influence the SUT  Test Stub: Hand coded object used for testing  Test Spy: Verification occurs after the test method has been called  Mock Object: Expectations configured before calling tests  Fake Object: Typically, it implements the same functionality as the real DOC but in a much simpler way, no expectation are configured.
  • 8. Mock? Why?  Mock - a simulated object that mimics the behavior of a real object in controlled ways.
  • 9. Four phase testing Image From: xunit Test Patterns, G. Meszaros
  • 11. Effective test automation  After test generation by considering all paths and the features and organization specified, our test still may have these bad smells: – Slow Tests – Test Code Duplication – Obscure Tests – Buggy Tests
  • 13. Mockito, how to drink it? framework basics import static org.mockito.Mockito.*; //mock creation LinkedList mockedList = mock(LinkedList.class); //using mock object mockedList.add("one"); mockedList.clear(); //verification verify(mockedList).add("one"); verify(mockedList).clear(); Stub - Mockito can mock concrete classes, not only interfaces
  • 14. Mockito, how to drink it? framework basics  Return value thenReturn() when(mock.someMethod("some arg")).thenReturn("foo");  Stubbing voids requires doReturn() doReturn("bar").when(mock).foo();
  • 15. What else to use  PowerMock (private, final,static methods)  Jmockit (constructors and static methods mocking)  Hamcrest (library of matcher objects (also known as constraints or predicates) allowing 'match' rules to be defined declaratively)
  • 17. EXAMPLE: JUNIT + ROBOLECTRIC for Android  Android unit testing is tricky: – android.jar only contains mocked out .class files which leads to java.lang.RuntimeException: Stub!  TIPS: – Keep things simple by trying to make as many services as possible not dependent on the parts of the Android platform that are not compatible with a conventional JVM. – Robolectric to the rescue
  • 18. Unit test depending on Android api @RunWith(RobolectricTestRunner.class) public class PopularRoutesAdapterTest { private PopularRoutesAdapter adapter; @Before public void setUp() { adapter = new PopularRoutesAdapter( Robolectric.buildActivity(Activity.class).create().get(); } @Test public void testAddItem() { assertEquals(0, adapter.getCount()); adapter.addItem(new Route("Arnhem")); assertEquals(1, adapter.getCount()); } Special test runner coming with Robolectric Activity class is mocked by Robolectric
  • 19. General rules to remember  Mock it outside your code  If you cannot test your code -> then probably you should change it ;) cause its badly written  Test first  Only one concrete class , mock the rest  Only mock your neirest neighbour (Law of Demeter -> dont talk with strangers)  Think ;) and then write
  • 20. Robo-WTF Robolectric  Has Java implementations of class files for most of the Android API  Enables true unittesting, being not dependent on any network, hardware, device or database Roboguice  Guice for Robolectric  Dependency Injection based in Google Guice  Code bases DI instead of XML (like in Spring)
  • 21. Deckard  Combination of – Gradle / Maven – Robolectric – Junit  Example adds – Roboguice – Mockito
  • 22. DEMO
  • 23. Developers Not Writing Tests  Symptoms: – No tests can be found when you ask to see the • unit tests for a task, • customer tests for a User Story, – Lack of clarity about what a user story or task really means  Impact: – Lack of safety net – Lack of focus  Possible Causes: – Hard to Test Code? – Not enough time? – Don’t have the skills? – Have been told not to? – Don’t see the value? Robolectric for unittesting Espresso for scenario-testing
  • 24. Resources  https://github.com/ddoa/dea-code- examples/android-deckard-unittest/  http://pages.cpsc.ucalgary.ca/~maurer/upload s/SENG515615F2007/XUnitTestPattern.ppt  http://code.google.com/p/mockito/  https://docs.google.com/presentation/d/1J0W iFJI9wSkc3UMsNXYv8ixX5orjkYzduwyOalzEk jU/embed?hl=pl&size=l#slide=id.p5