Testing & Debugging Flashcards
Unit testing
A level of software testing where individual units are tested. (i.e. Testing a method by itself, isolated from the remainder of the program.) The hope is that once the individual pieces are tested and verified to be working, then the likelihood of the overall project working becomes much higher. For Java programs, a unit is usually a method.
Test coverage / Code coverage
A measure of the amount of source code that has been executed during testing, typically provided as a percentage of lines covered. When executing the set of tests, if any line of code is executed, that line is said to be covered. You can use a tool like EclEmma to measure this.
General practice is to strive for at least 80 percent coverage (higher is obviously better), but remember that 100 percent coverage does not mean that you have handled all possible test cases! It is not uncommon to have more than one test to cover a given unit. That is, it is possible, and is often recommended, to have tests that account for both expected and unexpected behaviour of a given unit.
Black-box testing
Testing a method without knowing its implementation.
White-box testing
Testing methods by taking their implementations into account, in contrast to black-box test ing; for example, by selecting boundary test cases and ensuring that all branches of the code are covered by some test case.
Boundary test cases
A test case involving values that are at the outer boundary of the set of legal values. For example, if a method is expected to work for all nonnegative integers, then 0 is a boundary test case.
Trace messages
A message that is printed during a program run for debugging purposes.
Test data
Input to test the program
Test driven development (TDD)
A programming practice in which tests are written before actual code is written. The goal of the programmer then becomes that of ensuring that they write code such that all the tests pass.
Assertion
A claim that a certain condition holds in a particular program location.
Assert statement
A statement wherein the developer is asserting that something needs to be true. Usually, if the assertion fails, code execution is halted. In the context of JUnit testing, built-in assertion mechanisms are provided by the Assertions class.
assertEquals
An inbuilt assertion used for asserting that the actual value of a variable (or the value returned by invoking a method) matches the expected value. Most unit tests will use this statement extensively.
In a JUnit class, what is the annotation for a test?
@Test
What is the proper syntax for a test that checks equality between a and b?
assertEquals(a, b);
* Note that additional parameters, such as an error message or a tolerance, can also be provided.
Debugging
The process of trouble-shooting errors in your code
What is the general process to debug code?
- Place a breakpoint
- Run the code in debug mode
- Use the “Variables View” in Eclipse to review the changes to variable values as the code is executed to see where the results being returned are unexpected
- Stop debugging when you think you’ve found the issue
- Edit your code and change the breakpoint location, if needed