mobile development - unit and automation testing
TRANSCRIPT
Jose García@jgarciabt
Manuel Vivo@manuelvicnt
What is it?
Part of the Software Development ProcessRequirements – 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
FizzBuzzHelper
RPSLSHelper
- 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