07 Laboratory Exercise 1
07 Laboratory Exercise 1
Laboratory Exercise
Writing Unit Tests Using White-Box Testing
Approach and JUnit Tool
Objective:
Materials:
Procedure:
1. Create a folder on your local drive with your name. (Ex. Jess_Diaz)
2. Open NetBeans IDE 8.2. Go to File > New Project. The New Project dialog box will appear. Select
Java in Categories > Java Application in Projects. Then, click the Next button.
3. Write TaxCalculator in Project Name and check the Use Dedicated Folder for Storing Libraries
option. Click Finish to create the project.
4. Go to File > New File. The New File dialog box will appear. Select Java in Categories > Java Class
in File Types. Then, click the Next button.
5. Write ItemTaxCalculator in Class Name and select taxcalculator in Package. Click Finish to
create the new class.
6. Write the following program in the ItemTaxCalculator class. The CalculateItemTax method will be
used to calculate an item sales tax.
package taxcalculator;
9. Write ItemTaxCalculatorTest in the Class name and write the package name taxcalculator in
Package. Tick all the checkbox options in Generated Code and Generated Comments. Click Finish
to create the unit test class and the Test Packages node.
Notes:
• When creating the unit test class, it is best to write the class name the same as the class (unit) to be tested
and; word "Test" should be affixed to the class name.
• The project requires a separate directory for the Test Packages to create tests. This directory will contain the
unit tests for the project.
• The package of class to be tested and the test class should be the same.
10. Go to the Projects directory to view the project. Your project directory for the current project should be
the same as Figure 1.
@Test
public void testCalculateItemTax() {
System.out.println("CalculateItemTax method");
ItemTaxCalculator instance = new ItemTaxCalculator ();
double itemPrice = 50.0;
double taxPercent = 1.0;
double expectedResult = 5.0;
Activity:
1. Using NetBeans IDE, extract and open the java zipped project LoginModule in 07 Software System
for Testing folder. This project contains functions that allow users to log in to and create an account
for the system . This also has functions that will compute basic salary based on hourly rate , hours
worked, and overtime.
2. Create unit tests for the following classes of the system that will result all into “passed”:
• VerifyUserLogin (remove 0.0 from the assertEquals statement)
• PayrollCalculator
3. Submit your output to your instructor. Your output will be graded based on the given rubric.
GRADING RUBRIC:
CRITERIA PERFORMANCE INDICATORS POINTS
Correctness The code produces the expected result. 30
Logic The code meets the specifications of the problem. 30
Efficiency The code is concise without sacrificing correctness and logic. 20
Syntax The code adheres to the rules of the programming language. 20
Total 100