Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing

 Testing

Oursky Limited

October 23, 2012
Tweet

More Decks by Oursky Limited

Other Decks in Programming

Transcript

  1. Faster Time taken to fix bugs 0 250 500 750

    1,000 Design Implementation QA Post-release Time taken to fix bugs Tuesday, 23 October, 12
  2. Better • Measurable / Indicative Test • Testable Code •

    Documentation: • Pandaform: Formula / Query Tuesday, 23 October, 12
  3. Testable Code = Quality? • Single Responsibility Principle • Number

    of tests for same functionality • Complexity of the code to test in isolation • Open-Closed Principle / LSP • Possiblility to “mock” an object? • The needs to rewrite test for change? Tuesday, 23 October, 12
  4. TDD • Design -> Implement -> Test • Design ->

    Test -> Implement Tuesday, 23 October, 12
  5. def hello(n, greeting="Hello "): """ return greeting for n times

    >>> hello(2, "Hello World") 'Hello WorldHello World' """ return n * greeting if __name__ == "__main__": import doctest doctest.testmod() Tuesday, 23 October, 12
  6. Design? • What if n is not integer? • How

    to express “Hello “ is the default argument? Tuesday, 23 October, 12
  7. def hello(n, greeting="Hello "): """ return greeting for n times

    >>> hello(2, "Hello World") 'Hello WorldHello World' n must be an integer >>> hello("Hey", "Hello ") Traceback (most recent call last): ... TypeError: n must be integer By default it repeat "Hello " for n times >>> hello(3) 'Hello Hello Hello ' """ if not isinstance(n, int): raise TypeError("n must be integer") return n * greeting if __name__ == "__main__": import doctest doctest.testmod() Tuesday, 23 October, 12
  8. Good Test? • Automated • Run often (everytime you hit

    :w) • Fast (Mocking DB / External Services / Email) Tuesday, 23 October, 12
  9. Bug Fixing • Convert bug into test that breaks •

    Pass the test • Helps prevent edge case & record issue numbers (formflow/tests/models/mysql.txt) Tuesday, 23 October, 12
  10. Other issues • Test Coverage • Test Private Code •

    Helps refactoring vs Change private code will break tests? • DB Test? • Fixtures, Setup / Tear Down • Integrate with version control Tuesday, 23 October, 12
  11. Suggested Todo • Google Testing Blog • Writing Testable Code

    http://googletesting.blogspot.hk/2008/08/by- miko-hevery-so-you-decided-to.html • Guide to write Testable Code http://misko.hevery.com/attachments/Guide- Writing%20Testable%20Code.pdf • Start writing test in your next project! Tuesday, 23 October, 12