PDI · Question #216
A developer at AW Computing is tasked to create the supporting test class for a programmatic customization that leverages records stored within the custom object, Pricing Structure c. AW Computing…
The correct answer is A. Use a Test Date Factory class. C. Use the Test. leadtear{} method. When testing Apex code that relies on a large number of existing records, developers can use a Test Data Factory to programmatically create the necessary test data or leverage the Test.loadData() method to import data from a static resource.
Question
A developer at AW Computing is tasked to create the supporting test class for a programmatic customization that leverages records stored within the custom object, Pricing Structure c. AW Computing has a complex pricing structure for each item on the store, spanning more than 500 records. Which two approaches can the developer use to ensure Pricing _Structure__c records are available when the test class is executed? Choose 2 answers
Options
- AUse a Test Date Factory class.
- BUse the @raTeat (seeAllData=true) annotation.
- CUse the Test. leadtear{} method,
- DUse without shering on the class declaration.
How the community answered
(26 responses)- A77% (20)
- B15% (4)
- D8% (2)
Why each option
When testing Apex code that relies on a large number of existing records, developers can use a Test Data Factory to programmatically create the necessary test data or leverage the `Test.loadData()` method to import data from a static resource.
A Test Data Factory class is a best practice for creating test data programmatically, allowing developers to generate a consistent and controlled set of records needed for various test scenarios without relying on actual organizational data.
The `@isTest(seeAllData=true)` annotation is deprecated and generally discouraged because it makes tests less reliable by exposing them to potentially inconsistent or changing organizational data, rather than isolated test data.
The `Test.loadData()` method allows developers to import test data from a static resource (a .csv file), which is particularly useful for setting up large volumes of data like 500+ Pricing Structure records efficiently for testing purposes.
Using `without sharing` on a class declaration affects the enforcement of sharing rules for the class when executed, but it does not provide a mechanism to create or load test data into the test context.
Concept tested: Apex test data creation methods
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data_make_data.htm
Topics
Community Discussion
No community discussion yet for this question.