views:

27

answers:

1

I am playing with Google Calendar API, creating some useful function.

I another hand, I want to do it right puting some useful doctest and starting agile development.

  • How to write doctest since the result of each function is not really predictible (Depending of what is new on the server) :

    >>> calendar = GoogleCalendar(user='blabla', password='blablabla')
    >>> calendar.list()
    [email protected]'s Calendar List
        0. ...
        ...
    
  • If I don't want to leave the password in the source code, How do I do ?

  • How to write test for all the function of a class without writing each time the same thing to each function ?

    >>> calendar = GoogleCalendar(user='blabla', password='blablabla')
    >>> calendar.myFunction()
    
  • For each function of GoogleCalendar, I will have to create first the object ?

Thank you for your help

+1  A: 

If you do decide to test an external service, you can use a test fixture:

  • Write a make_test_server() function, which will return a new server connection to simplify your tests.
  • Make it a test fixture (dummy of the server) make_dummy_test_server() with predictable output.
  • Test it, and make sure that all cases (connection errors, empty set returned) have been thought of.

It depends on how exhaustive your tests should be. If you are getting a lot of bugs from that area of code, then you might need more tests. If your code works, it might not be worth sweating.

Are you also doing code reviews? Systems testing? Unit testing is great, but make sure that you don't get too myopic.

wisty
Ok thank you for the advice.
Natim