OOP - Testing Objects Flashcards
Unit Test
Scripts designed to test the performance of a single function.
How to Use in a Sentence: “As the program scales, unit tests, will ensure classes will continue to behave as expected.”
Arrange
Top section of a test designed to include things to arrange or set up like creating variables or instances. Used in a sentence: “How do I want this test to act? What function will trigger the test and provide inputs?”
Act
A statement that is true or calls the method that we are testing. Used in a sentence: “How do I want this test to act? What function will trigger the test and provide inputs?”
Assert
Statements that verify whether the method being tested behaves as expected. Used in a sentence: “This test will assert that the data returned should be an integer.”
Import
A keyword that makes code in one module accessible in another. Used in a sentence: “I’m getting a NameError because I forgot to import the class.”
What are the two focus questions for our class unit tests?
classes and objects are responsible for tracking state and behavior. The class unit test should focus on:
1) For all relevant cases, are the attributes of an instance correct?
* *When we create an instance of this class, are the initial attributes set to what’s expected?
2) For all relevant cases, do the methods on an instance work as expected?
* *Can we call an instance method on an instance of this class, and do we observe the expected behavior?
As always, the actual test cases depend on the context of the particular class and feature. Some classes won’t have much in the way of state or behavior. Other classes will have very complex logic which will need to be thoroughly tested.
Module
Any .py file that contains functions, classes, variables, and/or other runnable code How to Use in a Sentence:"I used the math.Euler() from the Math module to calculate an angle"
Package
A collection of modules
How to Use in a Sentence: “The requests package contains modules to help us request data from the Internet.” “My package has custom configuration in its __init__.py file.”