The 4th Dnepropetrovsk iOS Practice Leaders Community Meet-Up, which took place onThursday, September 25.
Maxim Koshtenko, an iOS developer with 4+ years of experience in the area, held a presentation in which he told:
- about the most widespread problems which appear while writing tests and how to solve them;
- how to cover controllers with tests correctly and what should be visible in interface;
- why tests do not work for block-based and asynchronous code and how we can fix this;
- how to write tests for Core Data models;
- many other useful and interesting tips and tricks.
The presentation will be interesting for all iOS developers.
18. viewDidLoad
- should call helper methods
- each of the helper methods should
do just one thing (SOLID principles)
19. viewDidLoad
- should call helper methods
- each of the helper methods should
do just one thing (SOLID principles)
- write tests for each of the helper
methods
20. viewDidLoad
- should call helper methods
- each of the helper methods should
do just one thing (SOLID principles)
- write tests for each of the helper
methods
- test viewDidLoad calls helper
methods (partial mock)
26. /// Adds a block of code before/instead/after the current
`selector` for a specific instance.
- (id<AspectToken>)aspect_hookSelector:(SEL)selector
withOptions:(AspectOptions)options
usingBlock:(id)block
error:(NSError **)error;
!
/// Called after the original implementation (default)
AspectPositionAfter,
!
/// Will replace the original implementation.
AspectPositionInstead,
!
/// Called before the original implementation.
AspectPositionBefore,
Aspects
27. dealloc
✅ hook dealloc method of SUT when
setup
❓ record calling of the hook
❓ verify if hook is called after teardown
Aspects
28. dealloc
✅ hook dealloc method of SUT when
setup
✅ record calling of the hook
❓ verify if hook is called after teardown
Aspects
instance var
29. dealloc
✅ hook dealloc method of SUT when
setup
✅ record calling of the hook
✅ verify if hook is called after teardown
Aspects
instance var
XCTAssert
60. CoreData
- create protocol that has all model’s
properties defined
- conform NSManagedObject to the
protocol
61. CoreData
- create protocol that has all model’s
properties defined
- conform NSManagedObject to the
protocol
- create NSObject model just for
testing, conforms to the protocol
and @synthesize properties
72. CoreData
Advantages?
- no additional classes
- no dependence on external state
- close approximation to the
application environment
- we are able to create base test
class with a stack and subclass it
where we need
73. CoreData
Advantages?
- no additional classes
- no dependence on external state
- close approximation to the
application environment
- we are able to create base test
class with a stack and subclass it
where we need