Jose García
@jgarciabt
Manuel Vivo
@manuelvicnt
What is it?
Part of the Software Development Process
Requirements – Design – Construction – Testing – Deployment
Provides information about the quality of the
product or service under test
Test techniques include the process of executing
a program or application with the intent of finding
software bugs (errors or other defects)
Why bother? (as an Indie developer)
Find problems early
Cost of fixing the problem increases
Documentation: Your unit tests should be a
documentation for others
Facilitates change: Have the certainty that you
don’t break anything
Grow resiliently
Why bother? (as part of a company)
Your code meets the
requirements that
guided its design and
development
Achieves the general
result its
stakeholders desire
Regression
Testing
Automation
Testing
Why bother? (as part of a company)
Performs its
functions within an
acceptable time
Responds correctly
to all kinds of inputs
Performance
Testing
Unit Testing
Other Testing types
Alpha/Beta testing
Multi-variant testing
Accessibility testing
Security testing
Destructive testing
…
What is it?
Main Goal: Test classes in isolation
Individual units of source code are tested
Data validation
Interactions with other objects
Each test case is independent from the others
Example
How to write good UT
Answer these questions
What are you testing?
How to write good UT
Answer these questions
What are you testing?
What should it do?
How to write good UT
Answer these questions
What are you testing?
What should it do?
What is the actual output?
How can you get the output?
How to write good UT
Answer these questions
What are you testing?
What should it do?
What is the actual output?
How can you get the output?
Is that output expected?
How to write good UT
Write the tests before coding following the
requirements
Always follow the same approach
Arrange / Act / Assert
Given / When / Then
Fizz Buzz
Interview question designed to help filter out the
99.5% of programming job candidates
Take turns to count incrementally, replacing any
number divisible by 3 with the word “fizz”, and
any number divisible by five with the word “buzz”
Example: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz,
11, Fizz, 13, 14, FizzBuzz, …
Rock Paper Scissors Lizard Spock
Check out the repo: https://github.com/jgarciabt/FizzBuzz
Code structure
Game Controller
FizzBuzz
Helper
RPSLS
Helper
- getFizzBuzz() - whoWins()
- getFizzBuzz()
- whoWins()
Mocking
Mock external dependencies
It creates fake objects which allows you to:
Verify that a method has been called on that object
Return a specific result when you call the method
on a fake object
Throw an exception when you call the method on a
fake object
What to Unit test in Mobile
Value testing your Business Logic
Everything but
Views
Basic getters and setters
Interactions with the platform specific classes /
frameworks (JVM, Android or iOS classes)
Unit Testing on Android
JUnit
Unit testing framework for Java. It runs on the
JVM, no need to have Android devices connected
InstrumentationTestCase
Class provided by the Android SDK which allows
us to access the Android instrumentation (e.g.
Context)
Test Driven Development (TDD)
Write the test before the implementation
The test will fail
Implement the solution to make the test pass
(usually with the minimum amount of effort)
The test will pass
Refactor the code to acceptable standards
Do it again
UT/TDD in Practice
Avoid unreliable Tests
People with experience on TDD and confidence
on the quality of their code usually write the
code first and then they cover it with Unit Tests
All advantages?
Takes a lot of time and dedication
Mocking frameworks don’t always work as you
expect and some of them have restrictions
Extra methods in your classes to allow testing
All the methods to be tested public? :(
What is it?
Use of external software to control the execution
of tests
Play back predefined actions on the product /
service
Compare the results to the expected behaviour
Important for Continuous Integration (CI)
Why bother?
Regression testing can be laborious and time
consuming
Time == $;
Automation vs Manual testing
In Mobile dev
Test Views & check what is on the screen is
correct
Test App behaviour
Automate manual testing
Cross platform Testing
Calabash is a software for Automated testing for
mobile apps
Enables you to write and execute tests defined
using natural language that can be understood
by business experts and non-technical staff
Calabash
Check out the repo with our example:
https://github.com/jgarciabt/FizzBuzz_automation
@jgarciabt
@manuelvicnt

Mobile Development - Unit and Automation Testing

  • 2.
  • 4.
    What is it? Partof the Software Development Process Requirements – Design – Construction – Testing – Deployment Provides information about the quality of the product or service under test Test techniques include the process of executing a program or application with the intent of finding software bugs (errors or other defects)
  • 5.
    Why bother? (asan Indie developer) Find problems early Cost of fixing the problem increases Documentation: Your unit tests should be a documentation for others Facilitates change: Have the certainty that you don’t break anything Grow resiliently
  • 6.
    Why bother? (aspart of a company) Your code meets the requirements that guided its design and development Achieves the general result its stakeholders desire Regression Testing Automation Testing
  • 7.
    Why bother? (aspart of a company) Performs its functions within an acceptable time Responds correctly to all kinds of inputs Performance Testing Unit Testing
  • 8.
    Other Testing types Alpha/Betatesting Multi-variant testing Accessibility testing Security testing Destructive testing …
  • 10.
    What is it? MainGoal: Test classes in isolation Individual units of source code are tested Data validation Interactions with other objects Each test case is independent from the others
  • 11.
  • 12.
    How to writegood UT Answer these questions What are you testing?
  • 13.
    How to writegood UT Answer these questions What are you testing? What should it do?
  • 14.
    How to writegood UT Answer these questions What are you testing? What should it do? What is the actual output? How can you get the output?
  • 15.
    How to writegood UT Answer these questions What are you testing? What should it do? What is the actual output? How can you get the output? Is that output expected?
  • 16.
    How to writegood UT Write the tests before coding following the requirements Always follow the same approach Arrange / Act / Assert Given / When / Then
  • 20.
    Fizz Buzz Interview questiondesigned to help filter out the 99.5% of programming job candidates Take turns to count incrementally, replacing any number divisible by 3 with the word “fizz”, and any number divisible by five with the word “buzz” Example: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, …
  • 21.
    Rock Paper ScissorsLizard Spock
  • 22.
    Check out therepo: https://github.com/jgarciabt/FizzBuzz
  • 23.
    Code structure Game Controller FizzBuzz Helper RPSLS Helper -getFizzBuzz() - whoWins() - getFizzBuzz() - whoWins()
  • 25.
    Mocking Mock external dependencies Itcreates fake objects which allows you to: Verify that a method has been called on that object Return a specific result when you call the method on a fake object Throw an exception when you call the method on a fake object
  • 27.
    What to Unittest in Mobile Value testing your Business Logic Everything but Views Basic getters and setters Interactions with the platform specific classes / frameworks (JVM, Android or iOS classes)
  • 28.
    Unit Testing onAndroid JUnit Unit testing framework for Java. It runs on the JVM, no need to have Android devices connected InstrumentationTestCase Class provided by the Android SDK which allows us to access the Android instrumentation (e.g. Context)
  • 29.
    Test Driven Development(TDD) Write the test before the implementation The test will fail Implement the solution to make the test pass (usually with the minimum amount of effort) The test will pass Refactor the code to acceptable standards Do it again
  • 32.
    UT/TDD in Practice Avoidunreliable Tests People with experience on TDD and confidence on the quality of their code usually write the code first and then they cover it with Unit Tests
  • 33.
    All advantages? Takes alot of time and dedication Mocking frameworks don’t always work as you expect and some of them have restrictions Extra methods in your classes to allow testing All the methods to be tested public? :(
  • 35.
    What is it? Useof external software to control the execution of tests Play back predefined actions on the product / service Compare the results to the expected behaviour Important for Continuous Integration (CI)
  • 36.
    Why bother? Regression testingcan be laborious and time consuming Time == $; Automation vs Manual testing
  • 37.
    In Mobile dev TestViews & check what is on the screen is correct Test App behaviour Automate manual testing
  • 38.
    Cross platform Testing Calabashis a software for Automated testing for mobile apps Enables you to write and execute tests defined using natural language that can be understood by business experts and non-technical staff
  • 39.
    Calabash Check out therepo with our example: https://github.com/jgarciabt/FizzBuzz_automation
  • 41.