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

Testing your "TESTS"

Testing your "TESTS"

Proposal for PyDelhi Conference 2017

Aniket Maithani

January 25, 2017
Tweet

More Decks by Aniket Maithani

Other Decks in Education

Transcript

  1. $: whoami o Aniket Maithani o Codes in Python o

    Works @Corseco Technologies o Foodie o -----”MAI--_THA--_NI” o @2aniketmaithani o https://github.com/aniketmaithani
  2. TESTING 101 Test(s) in Software scenario refers to the investigating

    the internal “health” of the code about the quality of the product or service. As the number of possible tests for even simple software components is practically infinite, all software testing uses some strategy to select tests that are feasible for the available time and resources But testing cannot identify all the defects within software at all times
  3. Types of Testing TESTS UI MODULE FLOW Functional Testing Unit

    Testing Integration Testing AUTOMATED TESTING MANUAL TESTING
  4. PyTest • Easy To Use • Popular • Concise •

    Easy Assertions • Plugins • POWER OF FIXTURES!
  5. The objective of Unit testing is to isolate a unit

    and validate its correctness. Unit Testing
  6. How Py-Test discovers your tests?? Ø Filename should start from

    test_foo_bar_etc.py Ø Function name should be test_foo_bar_etc() Ø Configuration defined in setup.cfg or setup.ini settings file
  7. SETUP & TEARDOWN Ø When a setUp() method is defined,

    the test runner will run that method prior to each test. Likewise, if a tearDown() method is defined, the test runner will invoke that method after each test. Ø You can create a setUp and tearDown for a bunch of tests and define them in a parent class - so it would be easy for you to support such tests and update common preparations and clean ups.
  8. Fixtures Ø The purpose of test fixtures is to provide

    a fixed baseline upon which tests can reliably and repeatedly execute. Ø fixtures have explicit names and are activated by declaring their use from test functions, modules, classes or whole projects. Ø fixtures are implemented in a modular manner, as each fixture name triggers a fixture function which can itself use other fixtures. Ø fixture management scales from simple unit to complex functional testing, allowing to parametrize fixtures and tests according to configuration and component options, or to re-use fixtures across class, module or whole test session scopes.
  9. More About Fixture Ø Fixtures in Django [Example] Ø Tests

    for Fixtures Ø Fixing the ”Fixtures”
  10. MOCK v mock is a library for testing in Python.

    It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used. Installation is simple :
  11. Py.Test & PDB Ø Combine the power of PyTest and

    PDB for real time test assertions Ø Easy to Use Ø Powerful Ø Interactive Ø Real Time Analysis