Chapter 5. Writing Efficient and Useful Unit Tests

Unit testing is the single most important skill an application developer can master. Sadly, writing unit tests is rarely seen as exciting, let alone important. This chapter will focus on testing various Apex components. We will discuss what to test, when to write the tests, and most importantly, how to test. We will cover the following topics:

  • Why do we write unit tests?
  • What to test—discussing positive, negative, and role-based testing
  • When do we write unit tests?
  • How do we structure tests for speed and code reuse?
  • Mocking
  • Tips and tricks for efficient testing

Why do we write unit tests?

Often, it seems that the answer to why do we write unit tests is because Salesforce makes us do it! This, however, ...

Get Mastering Application Development with Force.com now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.