Testing Flashcards
How you can invoke actions and get attributes of component in jest framework?
Using cmp result from $T.createComponent callback (same way as in Aura cmp.get(‘v.attributeName’) or cmp.actionName())
What syntax is used to check result in jest?
expect(condition).toBe(boolean) or similar
What method is used to perform action after each test executed in jest?
afterEach(() => {})
Basic structure of Jest test?
// test suite
describe()
// specific test case
it() or test()
Which methods sObject provides for inspecting errors related to records?
addError(), hasErrors(), getErrors()
List is used to work with errors
Which method is used to obtain current url of Visualforce page/controller in unit test?
getParameters() from PageReference
Which exceptions cannout be caught?
- LimitException
- License-related exception
- Exceptions that are thrown by System.assert methods
Main considerations regarding @testSetup
- Any changes made to data are rolled back after each method execution.
- Can’t be used with SeeAllData = true
- Only one @testSetup can be defined for each Apex test class
How to test private method?
Using @testVisible annotation on method declaration
How to make tests run asynchronously?
- Using Test tab in Developer Console (Always Run Asynch checkbox)
- Apex Test Execution page.
NOTE: Apex Classes can only run with All Tests option
How to avoid mixed DML exception when running tests?
- Use @future method to create non-setup objects (or vice versa).
- Use runAs block
What can cause “You have uncommited work exception” when performing callout in est?
It’s occured when DML operation are performed first before callouts in the same transaction.
Where Code Coverage can be skipped?
When doing new Run in dev console or Apex Test Execution page
How create component in jest test?
$T.createComponent(componentName, params, renderOrNot)
How to set PageReference in test?
Test.setCurrentPage
If class annotated with SeeAllData = true and method with SeeAllData = false, will be existing data used in this method?
Yes. SeeAllData=true always overrides SeeAllData=false
How to prevent UNABLE_TO_LOCK_ROW?
Disable Paraller Apex Testing in Apex Test Execution.
How to run test using SOAP API?
RunTestsResult[] runTests(RunTestsRequest [])
How run tests asynchronously via apex?
ApexTestQueueItem
ApexTestResult
Where Store Only Aggregated Code Coverage option can be selected?
Apex Test Execution page
How to instantiate controller extension in test?
By passing StandardController into Controller Extension costructor