Câu 10: Certified Platform Developer II
@isTeststatic void testIncrement() {Account acct = new Account(Name = 'Test');acct.Number_Of_Times_Viewed__c = 0;insert acct;AuditUtil.incrementViewed(acct.Id);Account acctAfter = [SELECT Number_Of_Times_Viewed__c FROM Account WHERE Id = :acct.Id][0]System.assertEquals(1, acctAfter.Number_Of_Times_Viewed__c);}The test…
Nội dung câu hỏi
@isTeststatic void testIncrement() {Account acct = new Account(Name = 'Test');acct.Number_Of_Times_Viewed__c = 0;insert acct;AuditUtil.incrementViewed(acct.Id);Account acctAfter = [SELECT Number_Of_Times_Viewed__c FROM Account WHERE Id = :acct.Id][0]System.assertEquals(1, acctAfter.Number_Of_Times_Viewed__c);}The test method above calls an @future method that increments the Number_of_Times_Viewed__c value. The assertion is failing because theNumber_of_Times_Viewed__c equals 0. What is the optimal way to fix this?
Các lựa chọn
Đáp án được giữ gọn theo nhãn A, B, C, D trong phần bình chọn tương tác.
- A. Change the initialization to acct.Number_Of_Times_Viewed__c = 1.
- B. Add Test.startTest() before and Test.stopTest() after AuditUtil.incrementViewed. — đáp án hiện tại
- C. Add Test.startTest() before and Test.stopTest() after insert acct.
- D. Change the assertion to System.assertEquals(0, acctAfter.Number_Of_Times_Viewed__c).
Cộng đồng
0 bình luận công khai. Tên thành viên được ẩn một phần.