What do programmers write tests to do?
What are the two options for testing code?
What is a Unit Test?
A unit test is a test case using a single data set that tests a function/method or confirms the state of a component (class instance or object)
How do you confirm a software component it operational?
Software components can have their operation confirmed by using a number of data sets that reflect the operation of a component over a range of values.
Define Data Coverage
Define Code Coverage
What are the main gotcha’s to remember in code coverage tests?
- Check both upper and lower limit boundaries
What is the goal of unit testing?
Unit testing works on which principal?
The principal of applying assertions to method/function results
What are assertions?
An assertion is a way to confirm that a return value or object variable contains a value that is known to be correct.
eg. if (rectangle.getHeight() == height)System.out.println(“PASSED – Height set successfully”);elseSystem.out.println(“FAILED – Height set failed”);
How are Assertions used when developing unit tests?
Assertions are placed into unit tests to confirm or verify an expected result.
What annotation is used to mark the method as a test method?
@Test before the method
Give an example of a more general assertion that could be used for testing a result
@Test
public void testCalculateAmount() {
double expectedAmount = 1279.61;
Mortgage instance = new Mortgage(0.06,25,200000);
instance.calculateAmount();
int result =
instance.getAmount();
// Confirm values are the same
assertEquals (expectedAmount, result, 1.0E-6);}
(the last param is the accuracy since testing doubles “0.0001% accuracy”)
What are the 2 @Test options?
Expected=exception
Timeout=value in ms
What is the expected exception option?
@Test (expected = ArithmeticException.Class)
What is the timeout value option?
@Test (timeout = 10000)
What is the goal of Test Data Selection?
What is equivalence partitioning?
What are boundary conditions?
Boundary conditions are test cases that are at the edge of the acceptable data range.
What are boundary issues?
Many subtle errors will exist at the edges of ranges or at data size limits (array size limits)
- If a function has an integer input range of 10 to 20 inclusive for a parameter a full boundary condition test will include 10, 20, 9, and 21
What are the two types of data sets unit tests must include?
Normal Data Sets
- Typical use is to confirm operation and results of calculations
Non-Normal Data Sets
- Typical use is to confirm special cases and or expected error conditions
Name a source that could be used to generate a test data set?
The specification and/or use cases are an excellent source of the initial data sets that can be used to for test cases
What is a good test data set for VV and why?:
Test Case evaluation
Integer[] findMultiples (int[] values)
- Method will take an array of values and return an array of the values that more than once.
- The input array can be any array of integer values.
What are some examples of non normal data sets for the previous method?