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

Effective testing strategies to raise code quality

Swift India
February 09, 2019

Effective testing strategies to raise code quality

Swift India

February 09, 2019
Tweet

More Decks by Swift India

Other Decks in Technology

Transcript

  1. Test Doubles & Test Data (First class citizens for writing

    unit test) By MURALIDHARAN KATHIRESAN
  2. What makes code hard to test ? Let’s review some

    anti-patterns, code smells, and bad practices that we should avoid when writing testable code
  3. What makes a Good Unit Test ? Perform the bare

    minimum of work required to achieve its goal Be easy to understand Be easy to maintain Execute in a shorter period of time A descriptive test name Narrow and Focused
  4. Continued.. One assert per test method Avoid test interdependence Keep

    it short, sweet and visible Recognize test setup pain as a smell Add unit tests to Continuous integration build
  5. What we follow in News? JSON Parsing Tests Snapshot Tests

    ViewState Tests Presenter Tests UseCase Tests
  6. A test double is an object that can stand in

    for a real object in a test, similar to how a stunt double stands in for an actor in a movie. These are sometimes all commonly referred to as “mocks”, but it's important to distinguish between the different types of test doubles since they all have different uses. Test Doubles
  7. Dummy A dummy implementation is an object which is not

    used in our test. Basically, we merely use it to let compile the test.
  8. Stub A Stub is a dummy that returns a specific

    value because the rest of the system relying on this specific value to continue running in a test. A stub has no logic, and only returns what we tell it to return
  9. Spy A Spy dependency is a more powerful version of

    the Stub one. It provides information based on how its methods are called—like the parameters values and the exact order methods are called
  10. Mock A mock is similar to a spy and does

    a little more. It also tests behavior by having the assertion go into the mock itself
  11. testData() is a static function that create an object Only

    one testData() for type testData() can create an object passing no arguments as all its property have default values default values reuse existing testData() whatever is possible default values use nil when the property is optional Benefits of Test Data?
  12. Credits Special thanks to ○ Aaina vivek jain ○ Giuseppe

    basile who introduced me the concept of test doubles and helped me to write quality code!