Changes

Jump to navigation Jump to search
no edit summary
Line 27: Line 27:  
The project doesn't end here. As activities are diverse these will serve as good examples for other activities. They'll serve as guides for porting of existing and new activities. I'd also document my findings and write a wiki page on how to write tests for activities (with some examples), so that it can serve as a guide for new activity authors.
 
The project doesn't end here. As activities are diverse these will serve as good examples for other activities. They'll serve as guides for porting of existing and new activities. I'd also document my findings and write a wiki page on how to write tests for activities (with some examples), so that it can serve as a guide for new activity authors.
   −
I'll be using the unittest library for writing unit tests. Its easy to write unittest for functions, that's pretty standard.
+
* I'll be using the unittest library for writing unit tests. Its easy to write unittest for functions, that's pretty standard.
 +
* Testing the GUI is a bit complex, the initial strategy is to simulate GUI triggers, like a mouse click, key down event etc using the uitree module in the sugar3 toolkit.
   −
Testing the GUI is a bit complex, the initial strategy is to simulate GUI triggers, like a mouse click, key down event etc using the uitree module in the sugar3 toolkit.
+
# The initial GUI tests would be to check if all the buttons in the toolbar exists, and buttons and other elements on the screen/canvas exists as they are expected to. Basic structure of the code would look like:  
 
  −
* The initial GUI tests would be to check if all the buttons in the toolbar exists, and buttons and other elements on the screen/canvas exists as they are expected to.
  −
Basic structure of the code would look like:  
      
     root = uitree.get_root()
 
     root = uitree.get_root()
Line 43: Line 41:  
     assert (activity_button != None)
 
     assert (activity_button != None)
   −
* The second stage would be to test if the buttons work as expected, we'd get the button reference using the uitree module and use the do_action method to run that particular action.
+
# The second stage would be to test if the buttons work as expected, we'd get the button reference using the uitree module and use the do_action method to run that particular action.
 
     one_button = activity_node.find_child(name="1",
 
     one_button = activity_node.find_child(name="1",
 
                                           role_name="push button")
 
                                           role_name="push button")
Line 52: Line 50:  
     assert(result.get_text() == "1")
 
     assert(result.get_text() == "1")
   −
Another complex testing domain we need to care about is network dependent ones. For example to test the chat API's UI, we'd have to send in a few messages and check if they are displayed. To invoke the receive method we'd have to actually send in a message from a different chat activity to this one and then test if its working. This isn't a viable approach to test network based triggers. Instead we'd have to mock up the network bits. By that I mean if we have a ChatActivity class that runs the receive method on the "message received" event we'd make a mock class and change the trigger to a manual one. Just run the receive method with some test/dummy data and check if the UI is updated accordingly.  
+
* Another complex testing domain we need to care about is network dependent ones. For example to test the chat API's UI, we'd have to send in a few messages and check if they are displayed. To invoke the receive method we'd have to actually send in a message from a different chat activity to this one and then test if its working. This isn't a viable approach to test network based triggers. Instead we'd have to mock up the network bits. By that I mean if we have a ChatActivity class that runs the receive method on the "message received" event we'd make a mock class and change the trigger to a manual one. Just run the receive method with some test/dummy data and check if the UI is updated accordingly.  
    
To further explain my approach I'd like to take an example from the Chat Activity. In the chat activity class:
 
To further explain my approach I'd like to take an example from the Chat Activity. In the chat activity class:
33

edits

Navigation menu