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 Deep Drive in Test classes 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!

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()

Deep Drive in Test classes Video

Agenda:

  • Intro to Testing
  • Basic Testing
  • Types of Tests
  • Avoiding Limits and Async
  • External Integration Tests ( Mock Callouts )
  • Debugging Failed Tests
  • Recap
YouTube video
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

Amit Chaudhary
Amit Chaudhary

Amit Chaudhary is Salesforce Application & System Architect and working on Salesforce Platform since 2010. He is Salesforce MVP since 2017 and have 17 Salesforce Certificates.

He is a active blogger and founder of Apex Hours.

Articles: 461

3 Comments

  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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *