Scrum Breakfast this June will focus on the following guiding concerns:
• Understand unit testing fundamentals in Android/iOS development.
• Know why we need to write tests, how it helps to control code quality.
• Easy to write testable code with MVVM (Model–View–ViewModel) architecture.
• CI/CD setup using Jenkins and Gitlab to show unit test coverage.
3. What is Unit testing
● A unit test is a piece of a code that invokes another piece of code.
● Done during the development (coding phase) of an application by the
developers
● Isolate a section of code and verify its correctness
● A unit may be an individual function, procedure, module, or object
www.axon.vnfb.com/AxonActiveVietNam
4. Why writes test?
● Ability to refactor code with confidence
● Proof that your code actually works
● You get a low-level regression-test suite
● It reduces the cost of bugs
www.axon.vnfb.com/AxonActiveVietNam
6. Test Double
“Test double is a generic term for any case where you replace a production
object for testing purposes.”
- Martin Fowler
www.axon.vnfb.com/AxonActiveVietNam
7. Why using Test double
● Enable testing
● Ease testing
● Improve testing
www.axon.vnfb.com/AxonActiveVietNam
8. Type of Test Double
● Stubs
● Mocks
● Spy/Spies
● Fake
● Dummy
www.axon.vnfb.com/AxonActiveVietNam
9. Stubs
● Control indirect inputs to system under test
● Provide “canned responses” to the SUT
www.axon.vnfb.com/AxonActiveVietNam
10. Mock
● Used to verify if the SUT call specific
method of collaborator. (Indirect output)
● Behavior verification
www.axon.vnfb.com/AxonActiveVietNam
11. Spy
● Like mock, verify interaction
● Keep track of what methods are called, and what
arguments they are called with.
www.axon.vnfb.com/AxonActiveVietNam
12. Fake
● Replace a “depended-on component” with a
lighter weight implementation
● Can be used for input or output
www.axon.vnfb.com/AxonActiveVietNam
13. Dummy
● Never used
● Satisfy method parameters
● Easy to implement
www.axon.vnfb.com/AxonActiveVietNam
14. Why MVVM?
● Models hold application data.
● Views display visual elements and
controls on the screen.
● View models transform model
information into values that can be
displayed on a view.
www.axon.vnfb.com/AxonActiveVietNam
17. iOS Unit test
● Unit tests have their own
target in Xcode and are
written using the XCTest
framework
www.axon.vnfb.com/AxonActiveVietNam
18. iOS Unit test
● Setup and Teardown
● Test Assertion
○ Boolean Assertions
○ Nil and Non-nil Assertions
○ Equality and Inequality Assertions
○ Comparable Value Assertions
○ NSException Assertions
○ Failing Unconditionally
www.axon.vnfb.com/AxonActiveVietNam