Test lab 2: unit test plans. Learning objectives. By the end of this lab, you should
know: • How to write a unit test plan. • How to use assess a test set's code ...
Test lab 2: unit test plans Learning objectives By the end of this lab, you should know: • •
How to write a unit test plan. How to use assess a test set's code coverage.
Deliverables By the end of this lab, you should save and email the following documents to your teammates and to
[email protected]: • Unit test plan for Stutter • Code coverage report for sample Stutter test cases
Links •
Template unit test plan: http://sweb.uky.edu/~mahays2/CS485/sampletestplan.pdf
•
Code coverage plugin: http://update.eclemma.org/
•
Stutter: http://sweb.uky.edu/~mahays2/CS485/Stutter.java
•
Sample test cases: http://sweb.uky.edu/~mahays2/CS485/StutterTest.java
Part 1: unit test plan In the first part of the lab, you will fill in a template unit test plan for the program Stutter. Stutter is a program that counts repeated words in a file. Do not code actual JUnit test cases for Stutter. A typical unit test plan has 3 parts: 1. General information: test requirements, including test scope and stopping criteria. 2. Plan: high level design, including which functions are being tested by whom and when. 3. Specification: low level design, including a discussion of test methods used like code checklists and white/black box testing, as well as a space to record individual test cases as they are designed.
Part 2: code coverage lab In the second part of the lab, you will learn to assess a test set's code coverage. Code coverage is a common stopping criteria used in unit testing. The idea is: if you are executing every line of code at least once, you are probably making a reasonably good effort to find bugs. White-box testing in particular is specifically designed to achieve high code coverage. Setup: 1. Start Eclipse 2. Go to Help → Install software
3. In the wizard that appears, add the site http://update.eclemma.org/ 4. From the list of available software, check EclEmma and install it. 5. When prompted, restart Eclipse. (note: Eclipse may be hidden on restart; click the Eclipse icon on the Windows taskbar to make it reappear) 6. Make a new Java project called Stutter with the default parameters. 7. Make a new Class file also called Stutter and paste in the Stutter source code from the link above over the stub code. 8. Make a new JUnit Test Case for Stutter called StutterTest and paste in the JUnit code from the link above over the stub code. 9. Run the JUnit test to verify everything compiles. If you encounter problems, ask for help. To see what code the test covered: 1. In the Package Explorer, right-click on StutterTest → Coverage As → JUnit test 2. Open Stutter.java and notice now that the code is highlighted. ◦ Red code was not executed. ◦ Yellow code was partially executed (for instance: an if statement's condition was true, but never false). ◦ Green code was executed. To build the report to turn in: 1. 2. 3. 4.
Go to File → Export In the resulting dialog, expand Java and select Coverage Report. Click Next. In the resulting dialog, select your most recent session, select HTML as the format, and select a destination directory (put the results in a new directory called emma). 5. Click Finish. 6. Go to the emma directory you selected and open index.html to browse the results.
Turning in work When you are done with both tasks, ask Mark to come by to look at your test plan and your coverage report. At the end of class, zip the emma directory and email both the test plan and the zip to your teammates and to Mark.