Deep Drive in Test classes

While not always the most glamorous part of writing code, testing is an absolutely essential piece of any developer’s tool belt. We’ll talk about how Apex testing works, the various ways to generate test data, and also some advanced testing concepts. We’ll also dive into the different types of tests and how to debug testing issues. Come learn how to improve your testing skills and find out how it will make you a better developer!

Agenda:

  • Intro to Testing
  • Basic Testing
  • Types of Tests
  • Avoiding Limits and Async
  • External Integration Tests ( Mock Callouts )
  • Debugging Failed Tests
  • Recap

Why Test ?

  • Ensure code is working
  • 75% Code Coverage Required for Production
  • Catch bugs early
  • Prevent Regression

How to Create Test Data

  • Manually create it for each test
  • Load data via CSV Static Resource
  • Test Setup
  • Test Factory
Screen Shot 2020-06-05 at 3.37.57 PM.png

How to Create Test Data

  • Manually create it for each test
    • Pro: Variables in context
    • Con: Lots of duplicate code
  • Load data via CSV Static Resource
    • Pro: Don’t need to make code updates for record creation
    • Con: Might be harder to track changes to static resources
  • Test Setup
    • Pro: Reduce repetitive code
    • Con: Variables out of context
  • Test Factory
    • Pro: Single location to update schema in code
    • Con: Variables out of context

Asserts in Tests

  • Confirm that code works as you expect it to
  • System.assert(condition, msg)
  • System.assertEquals(expected, actual, msg)
  • System.assertNotEquals(expected, actual, msg)
  • What controls whether or not your tests pass

Tips to Increase Test Coverage

  • @TestVisible
  • Test.isRunningTest()
  • Test Driven Development (TDD)

Test Suites

  • Collection of tests
  • Useful to cover entire application
  • Help unrelated prevent regressions

System.runAs()

Code needs to be tested as different users. Create/find a user and test on their behalf. Only applies to sharing, not FLS. Useful for avoiding Mixed DML errors. Useful for testing a specific version of managed package.

Other Test Class Uses

  • Test.isRunningTest()
  • Test.setCreatedDate()
  • Test.setCurrentPage()

Recording

Date     : Saturday, Jun 06, 2020 10:00 AM EST (7:30 PM IST)
RSVP : https://trailblazercommunitygroups.com/e/mzmp8g/
Where : Online
Speaker : Adam Olshansky


Further learning

Please Subscribe to our YouTube channel to get notification for upcoming recording.

If you are new in Salesforce. Please check our free Salesforce Admin and Salesforce Developer training.

Thanks,
Salesforce Apex Hours

7,785 total views, 15 views today

2 thoughts on “Deep Drive in Test classes”

  1. Many Thanks for amazing video but video is trimmed at few places for example at 34:20 Adam talks about showing Account trigger but instead video skips to test class output automatically.

    Reply
    • Yes sorry for that, By mistake recording stopped due technical issue. But there is only one place its happened

      Reply

Leave a Comment