Ch6: Unit Testing Flashcards
Benefits of Testing
- Living documentation that is updated with codebase
- Ensures expected and consistent behavior
- Safeguard against creation of bugs during refactoring
Define Unit Testing
Breaks codebase into smallest building blocks: individual statements and methods. This form of automated testing addresses fundamental tasks of classes.
Name a common unit testing framework for Java
JUnit
Define Refactoring
Process of rewriting code without introducing new features
Name the Testing Best Practices
- AAAs
- Deterministic
- Relevant
- Meaningful
Define the AAAs testing best practice
Pattern to follow when writing tests
- ARRANGE variables
- ACT on methods
- ASSERT comparison of expected & actual values
Define the Deterministic testing best practice
Produce same outcome every run
Define the Relevant testing best practice
Group by related class and function
Define the Meaningful testing best practice
Don’t test trivial code (ex. getters/setters)
Describe JUnit
A commonly used Java testing framework. This library provides classes, methods, and assertions for writing an executing unit test.
Define Java Annotation
Formalized information about program that doesn’t directly affect code, but supplies directions to the compiler. Use @ symbol
@Test
Annotation indicating public void method is a test case
@Before
Annotated method setting up data or conditions that will be provided to every test in a class. (ex: creating instances of objects)
@After
Annotated method setting up conditions to meet after all tests in a suite are finished running. (ex: closing database connection)
List 4 Common Assertion Methods
assertEquals, assertFalse, assertTrue, assertNotNull