Unit/Mutation Testing Flashcards

1
Q

What do programmers write tests to do?

A
  • Confirm an understanding of the specification
  • Can ensure that all different aspects are verified
  • Can test individual components that are outside of normal view
    - Internal (private) classes /functions /methods that are not directly exposed or deep in the application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two options for testing code?

A
  • Code Trace
    - A code Trace is a static analysis that is done by viewing the code and walking through the code by hand.
    - Debugging to understand or manipulate operation.
  • Write coded tests to execute specific components of a program with particular data sets.
    - Add code using print to screen or print to file to confirm operation.
    - Add structured Unit Tests to the Project
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Unit Test?

A

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)

  • A unit test is constructed as a method of a special testing class that is not part of the application, but is included in the project.
  • Units tests may or may not ship with the source code of the product.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you confirm a software component it operational?

A

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.

  • In general, most methods / functions will require more than a single unit test to confirm operation.
  • The goal of unit testing is to provide tests that provide data coverage and code coverage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define Data Coverage

A
  • Testing that uses different data combinations of input data that will ensure that the range of acceptable and unacceptable will produce the correct results/
  • 100% data coverage indicates that ALL combinations of data sets have been supplied to the component being tested **
    • ** Generally not practical
      AIM to achieve 100% PRACTICAL data coverage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define Code Coverage

A
  • Testing that will ensure that all code paths have been executed at least once during the set of test cases used.
    • NOTE: Practical data coverage MUST yield 100% code coverage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the main gotcha’s to remember in code coverage tests?

A
  • Check both sides of OR statements in an IF

- Check both upper and lower limit boundaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the goal of unit testing?

A
  • Confirmation of expected operation
    - These are considered
    normal data sets
    - Use cases (supplied
    during specification
    development) are useful
    to develop meaningful
    test data sets
  • Confirmation of expected error conditions
    - These are considered to
    be non-normal datasets
    - Out of range data sets.
    invalid data should
    result in continued
    program operation
    using a standard error
    handling mechanism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Unit testing works on which principal?

A

The principal of applying assertions to method/function results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are assertions?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How are Assertions used when developing unit tests?

A

Assertions are placed into unit tests to confirm or verify an expected result.

  • If the assertion results in a true response value the test is said to pass
  • A false return value from an assertion is considered a fail
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What annotation is used to mark the method as a test method?

A

@Test before the method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Give an example of a more general assertion that could be used for testing a result

A

@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”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the 2 @Test options?

A

Expected=exception

Timeout=value in ms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the expected exception option?

A

@Test (expected = ArithmeticException.Class)

  • Used to manage cases where the pass case produces an exception
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the timeout value option?

A

@Test (timeout = 10000)

  • Used to manage cases where the function needs to provide a performance guarantee
17
Q

What is the goal of Test Data Selection?

A
  • Create test data sets that will produce examples of ALL expected results with a minimum number if test cases.
    • Equivalent - duplicate test cases should be removed
18
Q

What is equivalence partitioning?

A
  • Test cases that are “generally” the same.
    - A test case that will produce a result or code path that is identical to another test case that has already been executed. (note an if statement that imposes a limit must be created to test both sides)
    - Allows the tester to reduce the number of test cases that will be required to prove desired / documented operation.
19
Q

What are boundary conditions?

A

Boundary conditions are test cases that are at the edge of the acceptable data range.

  • Can include data range limits.
  • Can also include size limits.
  • Can include performance limits.
20
Q

What are boundary issues?

A

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

21
Q

What are the two types of data sets unit tests must include?

A

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

22
Q

Name a source that could be used to generate a test data set?

A

The specification and/or use cases are an excellent source of the initial data sets that can be used to for test cases

23
Q

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.

A
  • values = {1,10,100,1000,-100,200,10,10,1000}
  • return = {10,1000} or {1000,10} - Observations :
    ▪Data set contains a range of values (including negatives)
    ▪Multiple values are returned.
    ▪Some value are rejected.
    ▪The same negative and positive value is in the set (different numbers should be rejected)
    ▪The last value in the array is included in the set.
    ACCEPTABLE DATA SET
24
Q

What are some examples of non normal data sets for the previous method?

A
  • Empty
    ▪{} no values provided
    ▪Could return an empty set or throw exception
  • A set with no recurring data ▪{1,2,3,4,5,6,7,8,9,10}
    ▪Should return an empty se
25
Q

What is mutation testing and what does it involve?

A

Mutation testing:

  • Evaluates the quality of software tests.
  • Involved modifying a program’s source code in small ways.
  • A test suite (set of test cases) that does not detect and reject the mutated code is considered defective.
26
Q

Define Testing Automation

A
  • Any mechanism that can be executed
  • Report will be produces that summarizes the results of the test
  • Junit within Netbeans is an example of on automated test mechanism
    - All tests will run
    - A simple report summary (bar chart) is generated showing pass cases and fail cases.
    - Details of failures can be provided
27
Q

What are the 4 main ways that test automation can aid the tester and the testing process?

A

Speed - Tests can be executed without user intervention.
Efficiency - Test can be run independently of other development activities (multi-task)
Accuracy/Precision - The test will be the same each time.
Relentless - Test tools do not get tired or bored

28
Q

What is regression testing?

A

Running a series of previously successfully passed tests against a new version/revision of the application or component.

JUNIT provides an automated regression testing mechanism that can/should be used to ensure code modifications do not break existing functionality.

29
Q

Name two types of regression tests and an example application in an automated environment

A

White-Box Unit Testing
▪ All updates/revisions and verified against a set of units tests
▪ Can be integrated into the development process that will prevent revisions be accepted by the source control system unless all unit tests pass

Black-Box Integrated Test
▪ Result capture of integrated application is compared against a previous capture – Tools like diff (unix)
▪ Considered to be a compare against a GOLD-STANDA

30
Q

What are the three realities to keep in mind when using test automation?

A
  • Software may be changed / improved
    ▪Some tests may be invalidated with new versions of the software
  • Time spent on Testing (writing tests) will take time away from development
  • Invasive Testing may impact a real-running system.
    ▪ If an automated tool finds a bug, try to reproduce by hand to confirm.
31
Q

What types of mutations do you need to change?

A
  • Language independent
    • Value Mutations
    • Decision Mutations
    • Statement Mutations
  • Language dependent
32
Q

What are value mutations?

A

Changing constants, loop bounds (adding/subtracting values)

33
Q

What are decision mutations?

A

< will be changed to > or <=

34
Q

What are statement mutations?

A

swapping, deleting, duplicating lines of code

35
Q

What are some language dependent mutations?

A
  • changing modifiers from protected to public
  • changing between static / non static
  • delete member initialization (int x = 0;)
  • delete this.xxx
  • changing argument orders