41

Mobile Development - Unit and Automation Testing

Embed Size (px)

Citation preview

Page 1: Mobile Development - Unit and Automation Testing
Page 2: Mobile Development - Unit and Automation Testing

Jose García@jgarciabt

Manuel Vivo@manuelvicnt

Page 3: Mobile Development - Unit and Automation Testing
Page 4: Mobile Development - Unit and Automation Testing

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

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

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

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

Other Testing types

Alpha/Beta testing

Multi-variant testing

Accessibility testing

Security testing

Destructive testing

Page 9: Mobile Development - Unit and Automation Testing
Page 10: Mobile Development - Unit and Automation 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

Page 11: Mobile Development - Unit and Automation Testing

Example

Page 12: Mobile Development - Unit and Automation Testing

How to write good UT

Answer these questions

What are you testing?

Page 13: Mobile Development - Unit and Automation Testing

How to write good UT

Answer these questions

What are you testing?

What should it do?

Page 14: Mobile Development - Unit and Automation Testing

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

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

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
Page 18: Mobile Development - Unit and Automation Testing
Page 19: Mobile Development - Unit and Automation Testing
Page 20: Mobile Development - Unit and Automation Testing

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

Rock Paper Scissors Lizard Spock

Page 22: Mobile Development - Unit and Automation Testing

Check out the repo: https://github.com/jgarciabt/FizzBuzz

Page 23: Mobile Development - Unit and Automation Testing

Code structure

Game Controller

FizzBuzzHelper

RPSLSHelper

- getFizzBuzz() - whoWins()

- getFizzBuzz()- whoWins()

Page 24: Mobile Development - Unit and Automation Testing
Page 25: Mobile Development - Unit and Automation Testing

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
Page 27: Mobile Development - Unit and Automation Testing

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

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

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
Page 31: Mobile Development - Unit and Automation Testing
Page 32: Mobile Development - Unit and Automation Testing

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

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
Page 35: Mobile Development - Unit and Automation Testing

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

Why bother?

Regression testing can be laborious and time consuming

Time == $;

Automation vs Manual testing

Page 37: Mobile Development - Unit and Automation Testing

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

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

Calabash

Check out the repo with our example: https://github.com/jgarciabt/FizzBuzz_automation

Page 40: Mobile Development - Unit and Automation Testing
Page 41: Mobile Development - Unit and Automation Testing

@jgarciabt

@manuelvicnt