tangoclinh1995 / thehonorclub-mobileapp

The Honor Club's Mobile App Project for COMP 3111H
2 stars 1 forks source link

[Question] Unit Testing UI components #25

Closed cameronsuen closed 7 years ago

cameronsuen commented 7 years ago

I am having issues with testing the controller. Since the majority of the code is UI-related code (e.g. calling date/timepicker), it is very hard to unit test those and the coverage rate is very low(~50%), any ideas on how to unit test these, or should I leave them be at all?

image

image

tangoclinh1995 commented 7 years ago

In this situation, you canot directly interact with the UI, but basically what you want to achieve is to manipulate the ionicTimePicker and ionicDatePicker services. In particular, in you unit test, you want to be able to:

To acheive these, you need to, inject a "fake" ionicTimePicker and ionicDatePicker into your controller (basically insert fake objects instead of the real services), add a spy on functions openDatePicker and openTimePicker of those faked objects.

You can take a look that methods *spyOn, .and.callFake, .and.returnValue, ... in Jasmine documentation: https://jasmine.github.io/2.5/introduction.html#section-Spies

sleeplessclassics commented 7 years ago

I can help you out with the unit testing for Events.