mobile development - unit and automation testing
TRANSCRIPT
![Page 1: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/1.jpg)
![Page 2: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/2.jpg)
Jose García@jgarciabt
Manuel Vivo@manuelvicnt
![Page 3: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/3.jpg)
![Page 4: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/4.jpg)
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)
![Page 5: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/5.jpg)
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
![Page 6: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/6.jpg)
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
![Page 7: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/7.jpg)
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
![Page 8: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/8.jpg)
Other Testing types
Alpha/Beta testing
Multi-variant testing
Accessibility testing
Security testing
Destructive testing
…
![Page 9: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/9.jpg)
![Page 10: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/10.jpg)
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
![Page 11: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/11.jpg)
Example
![Page 12: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/12.jpg)
How to write good UT
Answer these questions
What are you testing?
![Page 13: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/13.jpg)
How to write good UT
Answer these questions
What are you testing?
What should it do?
![Page 14: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/14.jpg)
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?
![Page 15: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/15.jpg)
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?
![Page 16: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/16.jpg)
How to write good UT
Write the tests before coding following the requirements
Always follow the same approach
Arrange / Act / Assert
Given / When / Then
![Page 17: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/17.jpg)
![Page 18: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/18.jpg)
![Page 19: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/19.jpg)
![Page 20: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/20.jpg)
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, …
![Page 21: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/21.jpg)
Rock Paper Scissors Lizard Spock
![Page 22: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/22.jpg)
Check out the repo: https://github.com/jgarciabt/FizzBuzz
![Page 23: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/23.jpg)
Code structure
Game Controller
FizzBuzzHelper
RPSLSHelper
- getFizzBuzz() - whoWins()
- getFizzBuzz()- whoWins()
![Page 24: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/24.jpg)
![Page 25: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/25.jpg)
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
![Page 26: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/26.jpg)
![Page 27: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/27.jpg)
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)
![Page 28: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/28.jpg)
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)
![Page 29: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/29.jpg)
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
![Page 30: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/30.jpg)
![Page 31: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/31.jpg)
![Page 32: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/32.jpg)
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
![Page 33: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/33.jpg)
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? :(
![Page 34: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/34.jpg)
![Page 35: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/35.jpg)
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)
![Page 36: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/36.jpg)
Why bother?
Regression testing can be laborious and time consuming
Time == $;
Automation vs Manual testing
![Page 37: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/37.jpg)
In Mobile dev
Test Views & check what is on the screen is correct
Test App behaviour
Automate manual testing
![Page 38: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/38.jpg)
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
![Page 39: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/39.jpg)
Calabash
Check out the repo with our example: https://github.com/jgarciabt/FizzBuzz_automation
![Page 40: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/40.jpg)
![Page 41: Mobile Development - Unit and Automation Testing](https://reader036.vdocuments.us/reader036/viewer/2022062905/58707f911a28ab57368b608b/html5/thumbnails/41.jpg)
@jgarciabt
@manuelvicnt