Testing Flashcards
What does testing framework allow us to do?
Write unit tests
What do test classes contain?
test classes contain unit tests
What are unit tests?
methods that verify a specific piece of code is behaving correctly
How should we name our test classes?
Name them after the class (for example: AccountTriggerHandler - AccountTriggerHandlerTest)
Test Methods
- Take no Arguments
- Return no Values
- Must be Static
What are the Asserting Values for Test Methods when writing system class methods?
- Assert
- assertEquals
- assertNotEquals
Data in Test classes cannot by default do what?
by default, you cannot access org data
you can give access, but should avoid doing so
When is TestSetup executed?
TestSetup is executed before each individual method
SOQL will only return what?
SOQL will only return records generated in the method or in the test method
SOSL will return what?
SOSL will return an empty list
What do Test Utility Classes have?
Test Utility Classes have reusable code that can be called by multiple test classes
What is TDD?
Test-Driven Development
It is a process that has use cases or requirements that are turned into test classes.
What are the disadvantages of Manual testing?
It is inefficient since you act as an end user and have to go through the same process each time
Why do we write unit tests for our code?
It ensures that our code meets the quality standards and produces the results needed for our production.
Allows code to be routinely tested whenever an update happens to ensure there is no code regression.
What is some best practice to follow when writing test code?
It is recommended to write test code for one piece of our application at a time. We don’t want to write test code for our entire application at once.
What is the @isTest annotation?
signifies that an apex class is a test class or that an apex method is a test method
test methods are contained within a test class using the @isTest annotation
Where is the @isTest annotation used?
In an apex test method and an apex test class
What is a naming ‘best practice’ for test classes and methods?
Name the test class and method after the class and method that is being tested. (ex: ApexClassName - ApexClassNameTest)
What are asserting values?
System class methods that are used in test classes and don’t return a value.
What should be your first choice of tool when it comes to testing?
Dummy data to make sure your tests are testing the right functionality
What is a common term for dummy data?
CSV of data
A Utility class can be used by…
multiple test classes as opposed to being called by only a single class.
What does @testVisible do?
Makes private class members accessible by test classes
@isTest(seeAllData=true)
- by default is set to false,
- setting it to true gives test access to your org
What are the 2 main uses for Test.StartTest() and Test.StopTest()?
- They provide new context for the tests within specific governor limits
- You can force Asynchronous code to behave synchronously
What does System.Assert do?
Lets us evaluate the condition given and if it is true, the test passes. otherwise the test fails
What does System.AssertEquals() do?
takes in two values and the first value is the expected value, so what you are expecting is going to be returned. the Second value is the returned value. if they are the same, then the test passes
What does System.AssertNotEquals() do?
Works the same way as System.AssertEquals(), but if they do NOT match, the test succeeds.
What does System.RunAs(){} do?
Tests the code when running it as a different user.
What are some ways of Test Execution?
- within the developer console
- in vs code
- Test Execution UI
- Running tests with API
What is our code coverage percentage?
Code coverage percentage represents how much of our code has been covered by unit tests. 75% in order to send to production.
How much code coverage percentage is the minimum for triggers?
1%
Testing best practices -Positive
- Ensure the expected behavior occurs when the user correctly makes use of it
- If everything is correct, we get the correct answer
testing best practices -Negative
Test to ensure that if things are not correctly used, are we handling it gracefully, and the errors being returned are the correct ones
Testing best practices -Single Action
Pass in a single record, does it execute correctly?
Testing best practices - Bulk Testing
Pass in multiple records, 200, is there a certain point to where our code cannot handle records being passed in
Testing best practices -Restricted User
Are we sharing, or not sharing, access as is appropriate