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

Score the Tendulkar Test Coverage

Score the Tendulkar Test Coverage

Simple coding principles and design patterns you can follow to make your code testable and achieve organic and high test coverage

Gopal S Akshintala

September 10, 2022

More Decks by Gopal S Akshintala

Other Decks in Programming


  1. Gopal S Akshintala Engineering Lead, Salesforce Community Day 2022 September

    10th, 2022 T-Hub, Hyderabad @GopalAkshintala overfullstack.ga
  2. Why Unit Test? @GopalAkshintala Find Bugs Statement Coverage Behaviour documentation

    in form of code Strive for behaviour coverage NOT Statement coverage
  3. What makes Unit Testing Di ffi cult? 😓 @GopalAkshintala Code

    Smells void methods static methods that are not static Bad Design Legacy Code interactions
  4. The Unstoppable Hammer! OOps! @GopalAkshintala Suppress this and super constructor

    static init blocks Stub private methods static methods final methods Constructors Mock final classes
  5. The Dark Powers 👹 Synthetic coverage is dangerous PowerMock is

    a new framework to learn Involves a lot of Setup and trail-and-error to get it right Tests written with PowerMock are brittle and difficult to Maintain It’s not Transparent OOps! @GopalAkshintala
  6. PowerMock Compatibility Incompatible with JUnit 5 JUnit 5 was release

    5 years ago Incompatible with Latest Mockito Latest Mockito: 4.20 Compatible version: 3.12 Not fully compatible with Java 11 OOps! @GopalAkshintala
  7. But do I need Unit Tests at all? Can’t I

    get Coverage with Integration Tests!? 🤷 @GopalAkshintala
  8. @GopalAkshintala ITests Vs UTests Use-case: How customer uses ITests should

    test Features Use-cases : Features : Components 1 Feature: Reflects software Functionality UTests should test Component Behaviour N N
  9. @GopalAkshintala ITests Vs UTests Traceability - How well a given

    test can precisely trace/pinpoint the cause of failure when it fails Productivity - Writing, Executing and Maintaining effort
  10. @GopalAkshintala Pure Vs Impure Pure Logic Impure Side-Effects REST I/O

    DB I/O Events • Data-in 
 Data-out • Referentially Transparent
  11. @GopalAkshintala Impure Pure static void add(int a, int b, Consumer<Integer>

    consumer) { consumer.accept(a + b); } / / Function call in Prod add(1, 2, System.out :: println); / / Function call in Test add(1, 2, result -> assertEquals(3, result));
  12. @GopalAkshintala Black box Unit Testing Unit Test ! = Test

    Internals Unit Test == E2E test for the Component
  13. @GopalAkshintala Anti-Patterns (digitaltapestry.net) https://confluence.internal.salesforce.com/display/TESTSFDC/ Unit+Testing+Best+Practices https://confluence.internal.salesforce.com/display/TESTSFDC/ Unit+Test+Recipes%3A+How+to+Write+High-Quality+Tests Explanation how proxy

    based Mock Frameworks work Write tests. Not too many. Mostly integration. (kentcdodds.com) Testing of Microservices - Spotify Engineering : Spotify Engineering (atspotify.com) On the Diverse And Fantastical Shapes of Testing (martinfowler.com) ongoing by Tim Bray · Testing in the Twenties (tbray.org) Resources
  14. No one gives you Change, you need to bring Change

    - Ramulu, Bus conductor #dadJoke