SlideShare a Scribd company logo
Unit Testing in Android
By Shamsul Arafin Mahtab
Software Engineer,
M2SYS Technology
Presentation Slide
What Should we know at first
2
➢ A type of software testing where individual units/ components
of a software are tested
➢ Done during the development (coding) of an application
➢ The objective of Unit Testing is to verify its correctness
➢ Usually performed by the developer
➢ Tools that we use in Android: JUnit4
What is Unit Testing’s Job
3
Ensuring that ‘the thing’ does what it is supposed to do
Code Structure in Android
4
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class NumberValidatorTest {
/** SystemUnderTest */
NumberValidator SUT;
@Before
public void setUp() throws Exception {
SUT = new NumberValidator();
}
/** Naming unitOfWork_stateUnderTest_expectedBehaviour */
@Test
public void checkPositive_correct_trueReturned() {
}
@After
public void tearDown() throws Exception {
}
}
Press Ctrl+Shift+T for a new Test class.
Example 1
5
Example 1 – Number Validator
6
public class NumberValidatorTest {
NumberValidator SUT;
@Before
public void setUp() throws Exception {
SUT = new NumberValidator();
}
@Test
public void checkPositive_positive_trueReturned() {
boolean result = SUT.isPositiveNumber(2);
Assert.assertThat(result, CoreMatchers.is(true));
}
@Test
public void checkPositive_zero_falseReturned() {
boolean result = SUT.isPositiveNumber(0);
Assert.assertThat(result, CoreMatchers.is(false));
}
@Test
public void checkPositive_negative_falseReturned() {
boolean result = SUT.isPositiveNumber(-1);
Assert.assertThat(result, CoreMatchers.is(false));
}
}
Example 1 – Test Output
7
Current Implementation
Example 2 – Boundary Check
8
Example 2 – Overlapping Detector
9
Test Cases
1. Interval1 before Interval2 (False)
2. Interval1 overlaps Interval2 on start (True)
3. Interval1 contained on Interval2 (True)
4. Interval1 contains Interval2 (True)
5. Interval1 overlaps Interval2 on end (True)
6. Interval1 after Interval2 (False)
7. Interval1 adjacent to Interval2 on start (True)
8. Interval1 adjacent to Interval2 on end (True)
Example 2 – Overlapping Detector
10
Run IntervalsOverlapDetectorTest with Coverage
Coverage Result
Introduction To Test Doubles
11
Why Test Double man!!
12
But if you have dependencies…..
Test Double Summary
13
➢ Used to substitute external unit dependencies in tests
➢ Three types of Test Doubles: Fake, Stub, Mock
➢ Fake: Functional implementation optimized for test
➢ Stub: Returns predefined data and can have programmable
behavior
➢ Mock: Records interactions with itself
➢ Mock is most used
List of Test Frameworks
14
Language Test Frameworks Mocking Frameworks
Java JUnit Mockito
Kotlin
Spek,
KotlinTest
Mockito-Kotlin,
MockK
Some Constraints
15
➢ Unit Test is not aware of Nullability
➢ Don’t use Singleton
➢ Static Methods has hidden dependencies, so can not be
substituted
➢ Can’t test on Android Frameworks
Where can we unit test in our app
16
UI Layer
Application Layer
Domain Layer
Infrastructure Layer
Espresso Test
Black Box v White Box testing
17
Black Box Testing
White Box Testing
Which one is better?
18
Test Driven Development to Rescue?
19
Uncle Bob’s Technique
20
1. You are not allowed to write any production code unless it is
to make a failing unit test pass
2. You are not allowed to write any more of a unit test than is
sufficient to fail and compilation failures are failures
3. You are not allowed to write any more production code than it
is sufficient to pass the one failing unit test
Your Decision
21
Be honest, do you like it to do when you will implement?
My Decision after the study
22
Thank You
23
Ad

More Related Content

What's hot (20)

N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
priya_trivedi
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
Frank Appel
 
API Testing following the Test Pyramid
API Testing following the Test PyramidAPI Testing following the Test Pyramid
API Testing following the Test Pyramid
Elias Nogueira
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Shailendra Chauhan
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
Manual Testing.
Manual Testing.Manual Testing.
Manual Testing.
Dhanasekaran Nagarajan
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
Sauce Labs
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
Knoldus Inc.
 
API Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj RollisonAPI Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj Rollison
TEST Huddle
 
Mobile application testing tutorial
Mobile application testing tutorialMobile application testing tutorial
Mobile application testing tutorial
Lokesh Agrawal
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
nickokiss
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Test Complete
Test CompleteTest Complete
Test Complete
RomSoft SRL
 
Manual testing real time questions by subbu
Manual testing real time questions by subbuManual testing real time questions by subbu
Manual testing real time questions by subbu
palla subrahmanyam
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Joe Tremblay
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
Francesco Garavaglia
 
Mobile application testing
Mobile application testingMobile application testing
Mobile application testing
vodQA
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
Lee Englestone
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
Frank Appel
 
API Testing following the Test Pyramid
API Testing following the Test PyramidAPI Testing following the Test Pyramid
API Testing following the Test Pyramid
Elias Nogueira
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
Sauce Labs
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
Knoldus Inc.
 
API Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj RollisonAPI Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj Rollison
TEST Huddle
 
Mobile application testing tutorial
Mobile application testing tutorialMobile application testing tutorial
Mobile application testing tutorial
Lokesh Agrawal
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
nickokiss
 
Manual testing real time questions by subbu
Manual testing real time questions by subbuManual testing real time questions by subbu
Manual testing real time questions by subbu
palla subrahmanyam
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Joe Tremblay
 
Mobile application testing
Mobile application testingMobile application testing
Mobile application testing
vodQA
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
Lee Englestone
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 

Similar to Unit Testing in Android (20)

Android testing part i
Android testing part iAndroid testing part i
Android testing part i
Kan-Han (John) Lu
 
Android testing
Android testingAndroid testing
Android testing
Bitbar
 
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
Rakuten Group, Inc.
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
RubenGray1
 
Unit testing basic
Unit testing basicUnit testing basic
Unit testing basic
Yuri Anischenko
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
DicodingEvent
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
Facundo Farias
 
SE2011_10.ppt
SE2011_10.pptSE2011_10.ppt
SE2011_10.ppt
MuhammedAlTijaniMrja
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testing
DanWooster1
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
Renato Primavera
 
1.1 Chapter_22_ Unit Testing-testing (1).pptx
1.1 Chapter_22_ Unit Testing-testing (1).pptx1.1 Chapter_22_ Unit Testing-testing (1).pptx
1.1 Chapter_22_ Unit Testing-testing (1).pptx
tiyaAbid
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
Pratik Patel
 
Automated Testing on iOS
Automated Testing on iOSAutomated Testing on iOS
Automated Testing on iOS
Make School
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
Priya Sharma
 
Automated Tests for Android apps
Automated Tests for Android appsAutomated Tests for Android apps
Automated Tests for Android apps
Clément Quaquin
 
Test driven development
Test driven developmentTest driven development
Test driven development
Sharafat Ibn Mollah Mosharraf
 
Beyond Agile Testing to Lean Development — Rakuten Technology Conference
Beyond Agile Testing to Lean Development — Rakuten Technology ConferenceBeyond Agile Testing to Lean Development — Rakuten Technology Conference
Beyond Agile Testing to Lean Development — Rakuten Technology Conference
James Coplien
 
Software testing definition
Software testing definitionSoftware testing definition
Software testing definition
Hiro Mia
 
Android testing
Android testingAndroid testing
Android testing
Bitbar
 
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
Rakuten Group, Inc.
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
RubenGray1
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
DicodingEvent
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testing
DanWooster1
 
1.1 Chapter_22_ Unit Testing-testing (1).pptx
1.1 Chapter_22_ Unit Testing-testing (1).pptx1.1 Chapter_22_ Unit Testing-testing (1).pptx
1.1 Chapter_22_ Unit Testing-testing (1).pptx
tiyaAbid
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
Pratik Patel
 
Automated Testing on iOS
Automated Testing on iOSAutomated Testing on iOS
Automated Testing on iOS
Make School
 
Automated Tests for Android apps
Automated Tests for Android appsAutomated Tests for Android apps
Automated Tests for Android apps
Clément Quaquin
 
Beyond Agile Testing to Lean Development — Rakuten Technology Conference
Beyond Agile Testing to Lean Development — Rakuten Technology ConferenceBeyond Agile Testing to Lean Development — Rakuten Technology Conference
Beyond Agile Testing to Lean Development — Rakuten Technology Conference
James Coplien
 
Software testing definition
Software testing definitionSoftware testing definition
Software testing definition
Hiro Mia
 
Ad

Recently uploaded (20)

How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Ad

Unit Testing in Android

  • 1. Unit Testing in Android By Shamsul Arafin Mahtab Software Engineer, M2SYS Technology Presentation Slide
  • 2. What Should we know at first 2 ➢ A type of software testing where individual units/ components of a software are tested ➢ Done during the development (coding) of an application ➢ The objective of Unit Testing is to verify its correctness ➢ Usually performed by the developer ➢ Tools that we use in Android: JUnit4
  • 3. What is Unit Testing’s Job 3 Ensuring that ‘the thing’ does what it is supposed to do
  • 4. Code Structure in Android 4 import org.junit.After; import org.junit.Before; import org.junit.Test; public class NumberValidatorTest { /** SystemUnderTest */ NumberValidator SUT; @Before public void setUp() throws Exception { SUT = new NumberValidator(); } /** Naming unitOfWork_stateUnderTest_expectedBehaviour */ @Test public void checkPositive_correct_trueReturned() { } @After public void tearDown() throws Exception { } } Press Ctrl+Shift+T for a new Test class.
  • 6. Example 1 – Number Validator 6 public class NumberValidatorTest { NumberValidator SUT; @Before public void setUp() throws Exception { SUT = new NumberValidator(); } @Test public void checkPositive_positive_trueReturned() { boolean result = SUT.isPositiveNumber(2); Assert.assertThat(result, CoreMatchers.is(true)); } @Test public void checkPositive_zero_falseReturned() { boolean result = SUT.isPositiveNumber(0); Assert.assertThat(result, CoreMatchers.is(false)); } @Test public void checkPositive_negative_falseReturned() { boolean result = SUT.isPositiveNumber(-1); Assert.assertThat(result, CoreMatchers.is(false)); } }
  • 7. Example 1 – Test Output 7 Current Implementation
  • 8. Example 2 – Boundary Check 8
  • 9. Example 2 – Overlapping Detector 9 Test Cases 1. Interval1 before Interval2 (False) 2. Interval1 overlaps Interval2 on start (True) 3. Interval1 contained on Interval2 (True) 4. Interval1 contains Interval2 (True) 5. Interval1 overlaps Interval2 on end (True) 6. Interval1 after Interval2 (False) 7. Interval1 adjacent to Interval2 on start (True) 8. Interval1 adjacent to Interval2 on end (True)
  • 10. Example 2 – Overlapping Detector 10 Run IntervalsOverlapDetectorTest with Coverage Coverage Result
  • 11. Introduction To Test Doubles 11
  • 12. Why Test Double man!! 12 But if you have dependencies…..
  • 13. Test Double Summary 13 ➢ Used to substitute external unit dependencies in tests ➢ Three types of Test Doubles: Fake, Stub, Mock ➢ Fake: Functional implementation optimized for test ➢ Stub: Returns predefined data and can have programmable behavior ➢ Mock: Records interactions with itself ➢ Mock is most used
  • 14. List of Test Frameworks 14 Language Test Frameworks Mocking Frameworks Java JUnit Mockito Kotlin Spek, KotlinTest Mockito-Kotlin, MockK
  • 15. Some Constraints 15 ➢ Unit Test is not aware of Nullability ➢ Don’t use Singleton ➢ Static Methods has hidden dependencies, so can not be substituted ➢ Can’t test on Android Frameworks
  • 16. Where can we unit test in our app 16 UI Layer Application Layer Domain Layer Infrastructure Layer Espresso Test
  • 17. Black Box v White Box testing 17 Black Box Testing White Box Testing
  • 18. Which one is better? 18
  • 19. Test Driven Development to Rescue? 19
  • 20. Uncle Bob’s Technique 20 1. You are not allowed to write any production code unless it is to make a failing unit test pass 2. You are not allowed to write any more of a unit test than is sufficient to fail and compilation failures are failures 3. You are not allowed to write any more production code than it is sufficient to pass the one failing unit test
  • 21. Your Decision 21 Be honest, do you like it to do when you will implement?
  • 22. My Decision after the study 22

Editor's Notes

  • #3: Here we can see a Popular News Paper of Bangladesh. To properly target NLP in Bengali we think to target on a specific domain such as Bangladesh topic, International topics, Politics, Economics, Sports, Entertainment, Education etc. That’s why we have target on Cricket to cover up the sports domain in Bengali Natural Language Processing.
  • #4: Here we can see a Popular News Paper of Bangladesh. To properly target NLP in Bengali we think to target on a specific domain such as Bangladesh topic, International topics, Politics, Economics, Sports, Entertainment, Education etc. That’s why we have target on Cricket to cover up the sports domain in Bengali Natural Language Processing.
  • #23: CNN is a class of deep, feed-forward artificial neural networks ( where connections between nodes do not form a cycle) & use a variation of multilayer perceptrons designed to require minimal preprocessing. These are inspired by animal visual cortex.