Assignment Prompt & Instructions
**files (8)**
– ## StringUtils3.java
– ## StringUtils2.java
– ## Proj5-ReportTemplate2.doc
– ## Proj5-ReportTemplate1.doc
– ## Project5-Instructions3.docx
– ## Project5-Instructions2.docx
– Project5.docx
– archive.zip
**## StringUtils3.java**
import java.security.InvalidParameterException;
/\*
\* Small class to practice writing JUnit tests
\* Author: Renata Rand McFadden
\* January 2016
*/
public class StringUtils {
// attributes
private String myStr;
// constructor
// assigns parameter value to myStr attribute
// throws NullPointerException if parameter is null or empty string
public StringUtils(String s)
{
if (s == null || s.equals(""))
{
throw new InvalidParameterException("Parameter cannot be null or empty");
}
myStr = s; // assign value of parameter to attribute
}
// constructor
// assigns parameter value to myStr attribute
// upper cases if parameter is true otherwise lower cases
// throws NullPointerException is parameter is null or empty string
public StringUtils(String s, boolean upper)
{
if (s == null)
{
throw new NullPointerException("Parameter cannot be null");
}
if (upper)
myStr = s.toUpperCase();
else
myStr = s.toLowerCase();
}
// returns current value of myStr attribute
public String getMyStr()
{
return myStr;
}
// returns true if myStr ends with character passed in parameter
// otherwise returns false
public boolean endsWithChar(char ch)
{
int last = myStr.length()-1;
if (myStr.charAt(last) == ch)
return true;
return false;
}
// converts myStr attribute to all upper case and returns result
public String convertToUpperCase()
{
String newStr = "";
for (int i=1; i < myStr.length(); i++)
{
char ch = myStr.charAt(i);
newStr = newStr + Character.toUpperCase(ch);
}
return newStr;
}
// returns character at index
// throws IndexOutOfBoundsException exception for out of bounds values
public char returnCharAt(int index)
{
if (index < 0 || index > myStr.length())
{
throw new NullPointerException("Index cannot be outsize of 0 and size of string");
}
return myStr.charAt(index);
}
// adds string in parameter to end of myStr
// returns new value and updates myStr
// throws InvalidParameterException if value is empty string or null
public String updateToConcat(String value)
{
if (value.equals(""))
{
throw new NullPointerException("Parameter cannot be empty string");
}
myStr = myStr.concat(value);
return myStr;
}
}
**## StringUtils2.java**
import java.security.InvalidParameterException;
/\*
\* Small class to practice writing JUnit tests
\* Author: Renata Rand McFadden
\* January 2016
*/
public class StringUtils {
// attributes
private String myStr;
// constructor
// assigns parameter value to myStr attribute
// throws NullPointerException if parameter is null or empty string
public StringUtils(String s)
{
if (s == null || s.equals(""))
{
throw new InvalidParameterException("Parameter cannot be null or empty");
}
myStr = s; // assign value of parameter to attribute
}
// constructor
// assigns parameter value to myStr attribute
// upper cases if parameter is true otherwise lower cases
// throws NullPointerException is parameter is null or empty string
public StringUtils(String s, boolean upper)
{
if (s == null)
{
throw new NullPointerException("Parameter cannot be null");
}
if (upper)
myStr = s.toUpperCase();
else
myStr = s.toLowerCase();
}
// returns current value of myStr attribute
public String getMyStr()
{
return myStr;
}
// returns true if myStr ends with character passed in parameter
// otherwise returns false
public boolean endsWithChar(char ch)
{
int last = myStr.length()-1;
if (myStr.charAt(last) == ch)
return true;
return false;
}
// converts myStr attribute to all upper case and returns result
public String convertToUpperCase()
{
String newStr = "";
for (int i=1; i < myStr.length(); i++)
{
char ch = myStr.charAt(i);
newStr = newStr + Character.toUpperCase(ch);
}
return newStr;
}
// returns character at index
// throws IndexOutOfBoundsException exception for out of bounds values
public char returnCharAt(int index)
{
if (index < 0 || index > myStr.length())
{
throw new NullPointerException("Index cannot be outsize of 0 and size of string");
}
return myStr.charAt(index);
}
// adds string in parameter to end of myStr
// returns new value and updates myStr
// throws InvalidParameterException if value is empty string or null
public String updateToConcat(String value)
{
if (value.equals(""))
{
throw new NullPointerException("Parameter cannot be empty string");
}
myStr = myStr.concat(value);
return myStr;
}
}
**## Proj5-ReportTemplate2.doc**
<Project 2>
<Project 5>
Unit Test
<Version>
<Date>
<Your Name>
**Table of Contents**
**11. Unit Test**
1.1 Approach
1
1.2 Test Cases
1
_1.2.1 Test Case 1 (example only)_
_1_
_1.2.2 Test Case 2 (example only)_
_1_
_1.2.3 Test Case 3_
_1_
**2. Defects**
**1**
2.1 Defects
1
_2.1.1 Defect 1_
_1_
_2.1.2 Defect 2_
_2_
**3. Other**
**2**
3.1 XXX
2
3.2 YYY
2
## 1. Unit Test
### 1.1 Approach
_Explain in this section here how unit test should be approached. Include in your discussion answers to the following questions: What are the goals and objectives for unit test? What are the key criteria for unit test? What kind of testing is unit test (black-box, white-box, boundary, etc.) and make sure to explain what that type of testing does? Who normally writes and executes unit test? As defects are found during unit test, what happens next? Who fixes them? Be as complete and thorough in your discussion demonstrating your knowledge of unit test_
### 1.2 Test Cases
#### 1.2.1 Test Case 1 (example only)
_Method being tested:_ isEmpty()
_Short Description:_ Test that when queue has no items, this method returns true
_Input Data to constructor and/or method you are testing:_ Create SimpleQueue with no elements
_Expected Results:_ method return value true
_Actual Results:_ **Passed:** method returned what was expected
#### 1.2.2 Test Case 2 (example only)
_Method being tested:_ getNumber()
_Short Description:_ Test that method currently returns the current value of the number attribute
_Input Data to constructor and/or method you are testing:_ Create instance of Account class passing it 5 for number value
_Expected Results:_ the value 5 is returned
_Actual Results:_ **Failed:** method threw an exception instead of returning value 5
#### 1.2.3 Test Case 3
_Method being tested:_
_Short Description:_
_Input Data to constructor and/or method you are testing:_
_Expected Results:_
_Actual Results:_
_…_
## 2. Defects
This section lists all identified defects
### 2.1 Defects
#### 2.1.1 Defect 1
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
#### 2.1.2 Defect 2
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
.
_…_
## 3. Other
_Put in this section any other findings or comments that do not fit in the above sections that you want to share with the instructor._
### 3.1 XXX
### 3.2 YYY
Software Unit Test
Page 1
**## Proj5-ReportTemplate1.doc**
<Project 2>
<Project 5>
Unit Test
<Version>
<Date>
<Your Name>
**Table of Contents**
**11. Unit Test**
1.1 Approach
1
1.2 Test Cases
1
_1.2.1 Test Case 1 (example only)_
_1_
_1.2.2 Test Case 2 (example only)_
_1_
_1.2.3 Test Case 3_
_1_
**2. Defects**
**1**
2.1 Defects
1
_2.1.1 Defect 1_
_1_
_2.1.2 Defect 2_
_2_
**3. Other**
**2**
3.1 XXX
2
3.2 YYY
2
## 1. Unit Test
### 1.1 Approach
_Explain in this section here how unit test should be approached. Include in your discussion answers to the following questions: What are the goals and objectives for unit test? What are the key criteria for unit test? What kind of testing is unit test (black-box, white-box, boundary, etc.) and make sure to explain what that type of testing does? Who normally writes and executes unit test? As defects are found during unit test, what happens next? Who fixes them? Be as complete and thorough in your discussion demonstrating your knowledge of unit test_
### 1.2 Test Cases
#### 1.2.1 Test Case 1 (example only)
_Method being tested:_ isEmpty()
_Short Description:_ Test that when queue has no items, this method returns true
_Input Data to constructor and/or method you are testing:_ Create SimpleQueue with no elements
_Expected Results:_ method return value true
_Actual Results:_ **Passed:** method returned what was expected
#### 1.2.2 Test Case 2 (example only)
_Method being tested:_ getNumber()
_Short Description:_ Test that method currently returns the current value of the number attribute
_Input Data to constructor and/or method you are testing:_ Create instance of Account class passing it 5 for number value
_Expected Results:_ the value 5 is returned
_Actual Results:_ **Failed:** method threw an exception instead of returning value 5
#### 1.2.3 Test Case 3
_Method being tested:_
_Short Description:_
_Input Data to constructor and/or method you are testing:_
_Expected Results:_
_Actual Results:_
_…_
## 2. Defects
This section lists all identified defects
### 2.1 Defects
#### 2.1.1 Defect 1
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
#### 2.1.2 Defect 2
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
.
_…_
## 3. Other
_Put in this section any other findings or comments that do not fit in the above sections that you want to share with the instructor._
### 3.1 XXX
### 3.2 YYY
Software Unit Test
Page 1
**## Project5-Instructions3.docx**
**Project 5**
**Unit Testing**
**Mission:**
You were asked by your manager to execute complete unit test (white box testing) for StringUtils Java class, written by a developer who suddenly left the team. You are provided the source code (StringUtils.java) and you are to write JUnit test cases for it. You are to assume that code description is correct for what each method is supposed to do and the code is supposed to match it.
**Objectives:**
Define, implement, and execute complete and thorough unit test on the given Java class (StringUtils.java).
**Outline of Steps:**
1. Fill out the Unit Test approach section in the template, explaining what unit test is all about and it’s most important criteria. Address all the questions completely and thoroughly.
2. Design tests for each method to meet 100% code coverage and reasonable data coverage. Describe these tests in the document using template format given. For this project you want to test methods against the code comments and the code itself. The code comments are assumed to be correct and the code may or may not be correct. Your goal is for your testcases to find defects in the code
3. Implement unit test cases in JUnit (e.g. StringUtilsTest.java)
4. Run the unit test cases and document the actual results in the report for each test case
5. Identify any defects you found running the JUnit and describe them in the report (using the template format) in section 2.
**Note:** You should find a few defects.
6. Submit both the report file and JUnit source code (java file).
7. All your tests must be in a single java file
Again, you should first identify and document in your report all the unit tests that should be created (using the example in report). That will give you partial credit – identifying the tests. Then you should implement those test cases in JUnit. Lastly you should run the test cases and document the actual results and defects you found.
**Resources:**
Proj5-MSIT660-GradingCriteria.doc – lists the grading criteria
Week 12-13 lecture charts – has unit test examples
ListNode.java and TestListNode.java – example Java class and its unit tests
Simple.java and testSimple.java – used in Discussions as examples of a class and JUnit tests for it.
List of assert methods that can be used in tests:
[http://junit.sourceforge.net/javadoc/org/junit/Assert.html](http://junit.sourceforge.net/javadoc/org/junit/Assert.html)
**Deliverables:**
Use the Report template (Pro5-ReportTemplate.doc) in Blackboard under Course Content->Projects->Project5 folder. The report must be submitted as an MS Word .doc. The name of the MS Word Report file shall be your_name_MSIT660_P6.doc. You must submit a separate file with your tests’ source code.
**Notes on pulling source code into eclipse**
1. Create a new Java project: File->New->Java Project (ex. MyProject5)
2. Click on “src” under your new project; right click and select import
3. Click on General->File System, then next and browse for where you have the file UTStringUtil.java, select it and click Finish
4. As an alternative you could create a new class StringUtils and copy/paste the file content into it.
5.
In your project, you will see the source file StringUtils.java under src directory.
**To add JUnit library to your Eclipse project:**
1. Right click on project and select Properties
2. Click on Java Build Path (left side list)
3. Click on “Add Library” button (right side)
4. Select JUnit and click next
5. Choose version 4 of Junit and click Finish
6. The JUnit library will now show under Libraries tab.
7. Click OK

**image1.png**
**## Project5-Instructions2.docx**
**Project 5**
**Unit Testing**
**Mission:**
You were asked by your manager to execute complete unit test (white box testing) for StringUtils Java class, written by a developer who suddenly left the team. You are provided the source code (StringUtils.java) and you are to write JUnit test cases for it. You are to assume that code description is correct for what each method is supposed to do and the code is supposed to match it.
**Objectives:**
Define, implement, and execute complete and thorough unit test on the given Java class (StringUtils.java).
**Outline of Steps:**
1. Fill out the Unit Test approach section in the template, explaining what unit test is all about and it’s most important criteria. Address all the questions completely and thoroughly.
2. Design tests for each method to meet 100% code coverage and reasonable data coverage. Describe these tests in the document using template format given. For this project you want to test methods against the code comments and the code itself. The code comments are assumed to be correct and the code may or may not be correct. Your goal is for your testcases to find defects in the code
3. Implement unit test cases in JUnit (e.g. StringUtilsTest.java)
4. Run the unit test cases and document the actual results in the report for each test case
5. Identify any defects you found running the JUnit and describe them in the report (using the template format) in section 2.
**Note:** You should find a few defects.
6. Submit both the report file and JUnit source code (java file).
7. All your tests must be in a single java file
Again, you should first identify and document in your report all the unit tests that should be created (using the example in report). That will give you partial credit – identifying the tests. Then you should implement those test cases in JUnit. Lastly you should run the test cases and document the actual results and defects you found.
**Resources:**
Proj5-MSIT660-GradingCriteria.doc – lists the grading criteria
Week 12-13 lecture charts – has unit test examples
ListNode.java and TestListNode.java – example Java class and its unit tests
Simple.java and testSimple.java – used in Discussions as examples of a class and JUnit tests for it.
List of assert methods that can be used in tests:
[http://junit.sourceforge.net/javadoc/org/junit/Assert.html](http://junit.sourceforge.net/javadoc/org/junit/Assert.html)
**Deliverables:**
Use the Report template (Pro5-ReportTemplate.doc) in Blackboard under Course Content->Projects->Project5 folder. The report must be submitted as an MS Word .doc. The name of the MS Word Report file shall be your_name_MSIT660_P6.doc. You must submit a separate file with your tests’ source code.
**Notes on pulling source code into eclipse**
1. Create a new Java project: File->New->Java Project (ex. MyProject5)
2. Click on “src” under your new project; right click and select import
3. Click on General->File System, then next and browse for where you have the file UTStringUtil.java, select it and click Finish
4. As an alternative you could create a new class StringUtils and copy/paste the file content into it.
5.
In your project, you will see the source file StringUtils.java under src directory.
**To add JUnit library to your Eclipse project:**
1. Right click on project and select Properties
2. Click on Java Build Path (left side list)
3. Click on “Add Library” button (right side)
4. Select JUnit and click next
5. Choose version 4 of Junit and click Finish
6. The JUnit library will now show under Libraries tab.
7. Click OK

**image1.png**
**Project5.docx**
This file is too large to display. [View in new window](https://www.sweetstudy.com/files/project5-docx-10531561)
**archive.zip**
This file is too large to display. [View in new window](https://www.sweetstudy.com/files/archive-zip-10531563)
**archive.zip**
This file is too large to display. [View in new window](https://www.sweetstudy.com/files/archive-zip-10531563)
**## StringUtils3.java**
import java.security.InvalidParameterException;
/\*
\* Small class to practice writing JUnit tests
\* Author: Renata Rand McFadden
\* January 2016
*/
public class StringUtils {
// attributes
private String myStr;
// constructor
// assigns parameter value to myStr attribute
// throws NullPointerException if parameter is null or empty string
public StringUtils(String s)
{
if (s == null || s.equals(""))
{
throw new InvalidParameterException("Parameter cannot be null or empty");
}
myStr = s; // assign value of parameter to attribute
}
// constructor
// assigns parameter value to myStr attribute
// upper cases if parameter is true otherwise lower cases
// throws NullPointerException is parameter is null or empty string
public StringUtils(String s, boolean upper)
{
if (s == null)
{
throw new NullPointerException("Parameter cannot be null");
}
if (upper)
myStr = s.toUpperCase();
else
myStr = s.toLowerCase();
}
// returns current value of myStr attribute
public String getMyStr()
{
return myStr;
}
// returns true if myStr ends with character passed in parameter
// otherwise returns false
public boolean endsWithChar(char ch)
{
int last = myStr.length()-1;
if (myStr.charAt(last) == ch)
return true;
return false;
}
// converts myStr attribute to all upper case and returns result
public String convertToUpperCase()
{
String newStr = "";
for (int i=1; i < myStr.length(); i++)
{
char ch = myStr.charAt(i);
newStr = newStr + Character.toUpperCase(ch);
}
return newStr;
}
// returns character at index
// throws IndexOutOfBoundsException exception for out of bounds values
public char returnCharAt(int index)
{
if (index < 0 || index > myStr.length())
{
throw new NullPointerException("Index cannot be outsize of 0 and size of string");
}
return myStr.charAt(index);
}
// adds string in parameter to end of myStr
// returns new value and updates myStr
// throws InvalidParameterException if value is empty string or null
public String updateToConcat(String value)
{
if (value.equals(""))
{
throw new NullPointerException("Parameter cannot be empty string");
}
myStr = myStr.concat(value);
return myStr;
}
}
**## StringUtils2.java**
import java.security.InvalidParameterException;
/\*
\* Small class to practice writing JUnit tests
\* Author: Renata Rand McFadden
\* January 2016
*/
public class StringUtils {
// attributes
private String myStr;
// constructor
// assigns parameter value to myStr attribute
// throws NullPointerException if parameter is null or empty string
public StringUtils(String s)
{
if (s == null || s.equals(""))
{
throw new InvalidParameterException("Parameter cannot be null or empty");
}
myStr = s; // assign value of parameter to attribute
}
// constructor
// assigns parameter value to myStr attribute
// upper cases if parameter is true otherwise lower cases
// throws NullPointerException is parameter is null or empty string
public StringUtils(String s, boolean upper)
{
if (s == null)
{
throw new NullPointerException("Parameter cannot be null");
}
if (upper)
myStr = s.toUpperCase();
else
myStr = s.toLowerCase();
}
// returns current value of myStr attribute
public String getMyStr()
{
return myStr;
}
// returns true if myStr ends with character passed in parameter
// otherwise returns false
public boolean endsWithChar(char ch)
{
int last = myStr.length()-1;
if (myStr.charAt(last) == ch)
return true;
return false;
}
// converts myStr attribute to all upper case and returns result
public String convertToUpperCase()
{
String newStr = "";
for (int i=1; i < myStr.length(); i++)
{
char ch = myStr.charAt(i);
newStr = newStr + Character.toUpperCase(ch);
}
return newStr;
}
// returns character at index
// throws IndexOutOfBoundsException exception for out of bounds values
public char returnCharAt(int index)
{
if (index < 0 || index > myStr.length())
{
throw new NullPointerException("Index cannot be outsize of 0 and size of string");
}
return myStr.charAt(index);
}
// adds string in parameter to end of myStr
// returns new value and updates myStr
// throws InvalidParameterException if value is empty string or null
public String updateToConcat(String value)
{
if (value.equals(""))
{
throw new NullPointerException("Parameter cannot be empty string");
}
myStr = myStr.concat(value);
return myStr;
}
}
**## Proj5-ReportTemplate2.doc**
<Project 2>
<Project 5>
Unit Test
<Version>
<Date>
<Your Name>
**Table of Contents**
**11. Unit Test**
1.1 Approach
1
1.2 Test Cases
1
_1.2.1 Test Case 1 (example only)_
_1_
_1.2.2 Test Case 2 (example only)_
_1_
_1.2.3 Test Case 3_
_1_
**2. Defects**
**1**
2.1 Defects
1
_2.1.1 Defect 1_
_1_
_2.1.2 Defect 2_
_2_
**3. Other**
**2**
3.1 XXX
2
3.2 YYY
2
## 1. Unit Test
### 1.1 Approach
_Explain in this section here how unit test should be approached. Include in your discussion answers to the following questions: What are the goals and objectives for unit test? What are the key criteria for unit test? What kind of testing is unit test (black-box, white-box, boundary, etc.) and make sure to explain what that type of testing does? Who normally writes and executes unit test? As defects are found during unit test, what happens next? Who fixes them? Be as complete and thorough in your discussion demonstrating your knowledge of unit test_
### 1.2 Test Cases
#### 1.2.1 Test Case 1 (example only)
_Method being tested:_ isEmpty()
_Short Description:_ Test that when queue has no items, this method returns true
_Input Data to constructor and/or method you are testing:_ Create SimpleQueue with no elements
_Expected Results:_ method return value true
_Actual Results:_ **Passed:** method returned what was expected
#### 1.2.2 Test Case 2 (example only)
_Method being tested:_ getNumber()
_Short Description:_ Test that method currently returns the current value of the number attribute
_Input Data to constructor and/or method you are testing:_ Create instance of Account class passing it 5 for number value
_Expected Results:_ the value 5 is returned
_Actual Results:_ **Failed:** method threw an exception instead of returning value 5
#### 1.2.3 Test Case 3
_Method being tested:_
_Short Description:_
_Input Data to constructor and/or method you are testing:_
_Expected Results:_
_Actual Results:_
_…_
## 2. Defects
This section lists all identified defects
### 2.1 Defects
#### 2.1.1 Defect 1
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
#### 2.1.2 Defect 2
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
.
_…_
## 3. Other
_Put in this section any other findings or comments that do not fit in the above sections that you want to share with the instructor._
### 3.1 XXX
### 3.2 YYY
Software Unit Test
Page 1
**## Proj5-ReportTemplate1.doc**
<Project 2>
<Project 5>
Unit Test
<Version>
<Date>
<Your Name>
**Table of Contents**
**11. Unit Test**
1.1 Approach
1
1.2 Test Cases
1
_1.2.1 Test Case 1 (example only)_
_1_
_1.2.2 Test Case 2 (example only)_
_1_
_1.2.3 Test Case 3_
_1_
**2. Defects**
**1**
2.1 Defects
1
_2.1.1 Defect 1_
_1_
_2.1.2 Defect 2_
_2_
**3. Other**
**2**
3.1 XXX
2
3.2 YYY
2
## 1. Unit Test
### 1.1 Approach
_Explain in this section here how unit test should be approached. Include in your discussion answers to the following questions: What are the goals and objectives for unit test? What are the key criteria for unit test? What kind of testing is unit test (black-box, white-box, boundary, etc.) and make sure to explain what that type of testing does? Who normally writes and executes unit test? As defects are found during unit test, what happens next? Who fixes them? Be as complete and thorough in your discussion demonstrating your knowledge of unit test_
### 1.2 Test Cases
#### 1.2.1 Test Case 1 (example only)
_Method being tested:_ isEmpty()
_Short Description:_ Test that when queue has no items, this method returns true
_Input Data to constructor and/or method you are testing:_ Create SimpleQueue with no elements
_Expected Results:_ method return value true
_Actual Results:_ **Passed:** method returned what was expected
#### 1.2.2 Test Case 2 (example only)
_Method being tested:_ getNumber()
_Short Description:_ Test that method currently returns the current value of the number attribute
_Input Data to constructor and/or method you are testing:_ Create instance of Account class passing it 5 for number value
_Expected Results:_ the value 5 is returned
_Actual Results:_ **Failed:** method threw an exception instead of returning value 5
#### 1.2.3 Test Case 3
_Method being tested:_
_Short Description:_
_Input Data to constructor and/or method you are testing:_
_Expected Results:_
_Actual Results:_
_…_
## 2. Defects
This section lists all identified defects
### 2.1 Defects
#### 2.1.1 Defect 1
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
#### 2.1.2 Defect 2
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
.
_…_
## 3. Other
_Put in this section any other findings or comments that do not fit in the above sections that you want to share with the instructor._
### 3.1 XXX
### 3.2 YYY
Software Unit Test
Page 1
**## Project5-Instructions3.docx**
**Project 5**
**Unit Testing**
**Mission:**
You were asked by your manager to execute complete unit test (white box testing) for StringUtils Java class, written by a developer who suddenly left the team. You are provided the source code (StringUtils.java) and you are to write JUnit test cases for it. You are to assume that code description is correct for what each method is supposed to do and the code is supposed to match it.
**Objectives:**
Define, implement, and execute complete and thorough unit test on the given Java class (StringUtils.java).
**Outline of Steps:**
1. Fill out the Unit Test approach section in the template, explaining what unit test is all about and it’s most important criteria. Address all the questions completely and thoroughly.
2. Design tests for each method to meet 100% code coverage and reasonable data coverage. Describe these tests in the document using template format given. For this project you want to test methods against the code comments and the code itself. The code comments are assumed to be correct and the code may or may not be correct. Your goal is for your testcases to find defects in the code
3. Implement unit test cases in JUnit (e.g. StringUtilsTest.java)
4. Run the unit test cases and document the actual results in the report for each test case
5. Identify any defects you found running the JUnit and describe them in the report (using the template format) in section 2.
**Note:** You should find a few defects.
6. Submit both the report file and JUnit source code (java file).
7. All your tests must be in a single java file
Again, you should first identify and document in your report all the unit tests that should be created (using the example in report). That will give you partial credit – identifying the tests. Then you should implement those test cases in JUnit. Lastly you should run the test cases and document the actual results and defects you found.
**Resources:**
Proj5-MSIT660-GradingCriteria.doc – lists the grading criteria
Week 12-13 lecture charts – has unit test examples
ListNode.java and TestListNode.java – example Java class and its unit tests
Simple.java and testSimple.java – used in Discussions as examples of a class and JUnit tests for it.
List of assert methods that can be used in tests:
[http://junit.sourceforge.net/javadoc/org/junit/Assert.html](http://junit.sourceforge.net/javadoc/org/junit/Assert.html)
**Deliverables:**
Use the Report template (Pro5-ReportTemplate.doc) in Blackboard under Course Content->Projects->Project5 folder. The report must be submitted as an MS Word .doc. The name of the MS Word Report file shall be your_name_MSIT660_P6.doc. You must submit a separate file with your tests’ source code.
**Notes on pulling source code into eclipse**
1. Create a new Java project: File->New->Java Project (ex. MyProject5)
2. Click on “src” under your new project; right click and select import
3. Click on General->File System, then next and browse for where you have the file UTStringUtil.java, select it and click Finish
4. As an alternative you could create a new class StringUtils and copy/paste the file content into it.
5.
In your project, you will see the source file StringUtils.java under src directory.
**To add JUnit library to your Eclipse project:**
1. Right click on project and select Properties
2. Click on Java Build Path (left side list)
3. Click on “Add Library” button (right side)
4. Select JUnit and click next
5. Choose version 4 of Junit and click Finish
6. The JUnit library will now show under Libraries tab.
7. Click OK

**image1.png**
**## Project5-Instructions2.docx**
**Project 5**
**Unit Testing**
**Mission:**
You were asked by your manager to execute complete unit test (white box testing) for StringUtils Java class, written by a developer who suddenly left the team. You are provided the source code (StringUtils.java) and you are to write JUnit test cases for it. You are to assume that code description is correct for what each method is supposed to do and the code is supposed to match it.
**Objectives:**
Define, implement, and execute complete and thorough unit test on the given Java class (StringUtils.java).
**Outline of Steps:**
1. Fill out the Unit Test approach section in the template, explaining what unit test is all about and it’s most important criteria. Address all the questions completely and thoroughly.
2. Design tests for each method to meet 100% code coverage and reasonable data coverage. Describe these tests in the document using template format given. For this project you want to test methods against the code comments and the code itself. The code comments are assumed to be correct and the code may or may not be correct. Your goal is for your testcases to find defects in the code
3. Implement unit test cases in JUnit (e.g. StringUtilsTest.java)
4. Run the unit test cases and document the actual results in the report for each test case
5. Identify any defects you found running the JUnit and describe them in the report (using the template format) in section 2.
**Note:** You should find a few defects.
6. Submit both the report file and JUnit source code (java file).
7. All your tests must be in a single java file
Again, you should first identify and document in your report all the unit tests that should be created (using the example in report). That will give you partial credit – identifying the tests. Then you should implement those test cases in JUnit. Lastly you should run the test cases and document the actual results and defects you found.
**Resources:**
Proj5-MSIT660-GradingCriteria.doc – lists the grading criteria
Week 12-13 lecture charts – has unit test examples
ListNode.java and TestListNode.java – example Java class and its unit tests
Simple.java and testSimple.java – used in Discussions as examples of a class and JUnit tests for it.
List of assert methods that can be used in tests:
[http://junit.sourceforge.net/javadoc/org/junit/Assert.html](http://junit.sourceforge.net/javadoc/org/junit/Assert.html)
**Deliverables:**
Use the Report template (Pro5-ReportTemplate.doc) in Blackboard under Course Content->Projects->Project5 folder. The report must be submitted as an MS Word .doc. The name of the MS Word Report file shall be your_name_MSIT660_P6.doc. You must submit a separate file with your tests’ source code.
**Notes on pulling source code into eclipse**
1. Create a new Java project: File->New->Java Project (ex. MyProject5)
2. Click on “src” under your new project; right click and select import
3. Click on General->File System, then next and browse for where you have the file UTStringUtil.java, select it and click Finish
4. As an alternative you could create a new class StringUtils and copy/paste the file content into it.
5.
In your project, you will see the source file StringUtils.java under src directory.
**To add JUnit library to your Eclipse project:**
1. Right click on project and select Properties
2. Click on Java Build Path (left side list)
3. Click on “Add Library” button (right side)
4. Select JUnit and click next
5. Choose version 4 of Junit and click Finish
6. The JUnit library will now show under Libraries tab.
7. Click OK

**image1.png**
**Project5.docx**
This file is too large to display. [View in new window](https://www.sweetstudy.com/files/project5-docx-10531561)
**archive.zip**
This file is too large to display. [View in new window](https://www.sweetstudy.com/files/archive-zip-10531563)
**## StringUtils3.java**
import java.security.InvalidParameterException;
/\*
\* Small class to practice writing JUnit tests
\* Author: Renata Rand McFadden
\* January 2016
*/
public class StringUtils {
// attributes
private String myStr;
// constructor
// assigns parameter value to myStr attribute
// throws NullPointerException if parameter is null or empty string
public StringUtils(String s)
{
if (s == null || s.equals(""))
{
throw new InvalidParameterException("Parameter cannot be null or empty");
}
myStr = s; // assign value of parameter to attribute
}
// constructor
// assigns parameter value to myStr attribute
// upper cases if parameter is true otherwise lower cases
// throws NullPointerException is parameter is null or empty string
public StringUtils(String s, boolean upper)
{
if (s == null)
{
throw new NullPointerException("Parameter cannot be null");
}
if (upper)
myStr = s.toUpperCase();
else
myStr = s.toLowerCase();
}
// returns current value of myStr attribute
public String getMyStr()
{
return myStr;
}
// returns true if myStr ends with character passed in parameter
// otherwise returns false
public boolean endsWithChar(char ch)
{
int last = myStr.length()-1;
if (myStr.charAt(last) == ch)
return true;
return false;
}
// converts myStr attribute to all upper case and returns result
public String convertToUpperCase()
{
String newStr = "";
for (int i=1; i < myStr.length(); i++)
{
char ch = myStr.charAt(i);
newStr = newStr + Character.toUpperCase(ch);
}
return newStr;
}
// returns character at index
// throws IndexOutOfBoundsException exception for out of bounds values
public char returnCharAt(int index)
{
if (index < 0 || index > myStr.length())
{
throw new NullPointerException("Index cannot be outsize of 0 and size of string");
}
return myStr.charAt(index);
}
// adds string in parameter to end of myStr
// returns new value and updates myStr
// throws InvalidParameterException if value is empty string or null
public String updateToConcat(String value)
{
if (value.equals(""))
{
throw new NullPointerException("Parameter cannot be empty string");
}
myStr = myStr.concat(value);
return myStr;
}
}
**## StringUtils2.java**
import java.security.InvalidParameterException;
/\*
\* Small class to practice writing JUnit tests
\* Author: Renata Rand McFadden
\* January 2016
*/
public class StringUtils {
// attributes
private String myStr;
// constructor
// assigns parameter value to myStr attribute
// throws NullPointerException if parameter is null or empty string
public StringUtils(String s)
{
if (s == null || s.equals(""))
{
throw new InvalidParameterException("Parameter cannot be null or empty");
}
myStr = s; // assign value of parameter to attribute
}
// constructor
// assigns parameter value to myStr attribute
// upper cases if parameter is true otherwise lower cases
// throws NullPointerException is parameter is null or empty string
public StringUtils(String s, boolean upper)
{
if (s == null)
{
throw new NullPointerException("Parameter cannot be null");
}
if (upper)
myStr = s.toUpperCase();
else
myStr = s.toLowerCase();
}
// returns current value of myStr attribute
public String getMyStr()
{
return myStr;
}
// returns true if myStr ends with character passed in parameter
// otherwise returns false
public boolean endsWithChar(char ch)
{
int last = myStr.length()-1;
if (myStr.charAt(last) == ch)
return true;
return false;
}
// converts myStr attribute to all upper case and returns result
public String convertToUpperCase()
{
String newStr = "";
for (int i=1; i < myStr.length(); i++)
{
char ch = myStr.charAt(i);
newStr = newStr + Character.toUpperCase(ch);
}
return newStr;
}
// returns character at index
// throws IndexOutOfBoundsException exception for out of bounds values
public char returnCharAt(int index)
{
if (index < 0 || index > myStr.length())
{
throw new NullPointerException("Index cannot be outsize of 0 and size of string");
}
return myStr.charAt(index);
}
// adds string in parameter to end of myStr
// returns new value and updates myStr
// throws InvalidParameterException if value is empty string or null
public String updateToConcat(String value)
{
if (value.equals(""))
{
throw new NullPointerException("Parameter cannot be empty string");
}
myStr = myStr.concat(value);
return myStr;
}
}
**## Proj5-ReportTemplate2.doc**
<Project 2>
<Project 5>
Unit Test
<Version>
<Date>
<Your Name>
**Table of Contents**
**11. Unit Test**
1.1 Approach
1
1.2 Test Cases
1
_1.2.1 Test Case 1 (example only)_
_1_
_1.2.2 Test Case 2 (example only)_
_1_
_1.2.3 Test Case 3_
_1_
**2. Defects**
**1**
2.1 Defects
1
_2.1.1 Defect 1_
_1_
_2.1.2 Defect 2_
_2_
**3. Other**
**2**
3.1 XXX
2
3.2 YYY
2
## 1. Unit Test
### 1.1 Approach
_Explain in this section here how unit test should be approached. Include in your discussion answers to the following questions: What are the goals and objectives for unit test? What are the key criteria for unit test? What kind of testing is unit test (black-box, white-box, boundary, etc.) and make sure to explain what that type of testing does? Who normally writes and executes unit test? As defects are found during unit test, what happens next? Who fixes them? Be as complete and thorough in your discussion demonstrating your knowledge of unit test_
### 1.2 Test Cases
#### 1.2.1 Test Case 1 (example only)
_Method being tested:_ isEmpty()
_Short Description:_ Test that when queue has no items, this method returns true
_Input Data to constructor and/or method you are testing:_ Create SimpleQueue with no elements
_Expected Results:_ method return value true
_Actual Results:_ **Passed:** method returned what was expected
#### 1.2.2 Test Case 2 (example only)
_Method being tested:_ getNumber()
_Short Description:_ Test that method currently returns the current value of the number attribute
_Input Data to constructor and/or method you are testing:_ Create instance of Account class passing it 5 for number value
_Expected Results:_ the value 5 is returned
_Actual Results:_ **Failed:** method threw an exception instead of returning value 5
#### 1.2.3 Test Case 3
_Method being tested:_
_Short Description:_
_Input Data to constructor and/or method you are testing:_
_Expected Results:_
_Actual Results:_
_…_
## 2. Defects
This section lists all identified defects
### 2.1 Defects
#### 2.1.1 Defect 1
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
#### 2.1.2 Defect 2
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
.
_…_
## 3. Other
_Put in this section any other findings or comments that do not fit in the above sections that you want to share with the instructor._
### 3.1 XXX
### 3.2 YYY
Software Unit Test
Page 1
**## Proj5-ReportTemplate1.doc**
<Project 2>
<Project 5>
Unit Test
<Version>
<Date>
<Your Name>
**Table of Contents**
**11. Unit Test**
1.1 Approach
1
1.2 Test Cases
1
_1.2.1 Test Case 1 (example only)_
_1_
_1.2.2 Test Case 2 (example only)_
_1_
_1.2.3 Test Case 3_
_1_
**2. Defects**
**1**
2.1 Defects
1
_2.1.1 Defect 1_
_1_
_2.1.2 Defect 2_
_2_
**3. Other**
**2**
3.1 XXX
2
3.2 YYY
2
## 1. Unit Test
### 1.1 Approach
_Explain in this section here how unit test should be approached. Include in your discussion answers to the following questions: What are the goals and objectives for unit test? What are the key criteria for unit test? What kind of testing is unit test (black-box, white-box, boundary, etc.) and make sure to explain what that type of testing does? Who normally writes and executes unit test? As defects are found during unit test, what happens next? Who fixes them? Be as complete and thorough in your discussion demonstrating your knowledge of unit test_
### 1.2 Test Cases
#### 1.2.1 Test Case 1 (example only)
_Method being tested:_ isEmpty()
_Short Description:_ Test that when queue has no items, this method returns true
_Input Data to constructor and/or method you are testing:_ Create SimpleQueue with no elements
_Expected Results:_ method return value true
_Actual Results:_ **Passed:** method returned what was expected
#### 1.2.2 Test Case 2 (example only)
_Method being tested:_ getNumber()
_Short Description:_ Test that method currently returns the current value of the number attribute
_Input Data to constructor and/or method you are testing:_ Create instance of Account class passing it 5 for number value
_Expected Results:_ the value 5 is returned
_Actual Results:_ **Failed:** method threw an exception instead of returning value 5
#### 1.2.3 Test Case 3
_Method being tested:_
_Short Description:_
_Input Data to constructor and/or method you are testing:_
_Expected Results:_
_Actual Results:_
_…_
## 2. Defects
This section lists all identified defects
### 2.1 Defects
#### 2.1.1 Defect 1
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
#### 2.1.2 Defect 2
**Method:** _Put here the method name that has a defect_
**Defect Description**:
_Put here, what behavior is incorrect and why you believe it’s a defect_
**How Found**:
_Explain how you were able to find this defect and which testcase found the issue_
.
_…_
## 3. Other
_Put in this section any other findings or comments that do not fit in the above sections that you want to share with the instructor._
### 3.1 XXX
### 3.2 YYY
Software Unit Test
Page 1
**## Project5-Instructions3.docx**
**Project 5**
**Unit Testing**
**Mission:**
You were asked by your manager to execute complete unit test (white box testing) for StringUtils Java class, written by a developer who suddenly left the team. You are provided the source code (StringUtils.java) and you are to write JUnit test cases for it. You are to assume that code description is correct for what each method is supposed to do and the code is supposed to match it.
**Objectives:**
Define, implement, and execute complete and thorough unit test on the given Java class (StringUtils.java).
**Outline of Steps:**
1. Fill out the Unit Test approach section in the template, explaining what unit test is all about and it’s most important criteria. Address all the questions completely and thoroughly.
2. Design tests for each method to meet 100% code coverage and reasonable data coverage. Describe these tests in the document using template format given. For this project you want to test methods against the code comments and the code itself. The code comments are assumed to be correct and the code may or may not be correct. Your goal is for your testcases to find defects in the code
3. Implement unit test cases in JUnit (e.g. StringUtilsTest.java)
4. Run the unit test cases and document the actual results in the report for each test case
5. Identify any defects you found running the JUnit and describe them in the report (using the template format) in section 2.
**Note:** You should find a few defects.
6. Submit both the report file and JUnit source code (java file).
7. All your tests must be in a single java file
Again, you should first identify and document in your report all the unit tests that should be created (using the example in report). That will give you partial credit – identifying the tests. Then you should implement those test cases in JUnit. Lastly you should run the test cases and document the actual results and defects you found.
**Resources:**
Proj5-MSIT660-GradingCriteria.doc – lists the grading criteria
Week 12-13 lecture charts – has unit test examples
ListNode.java and TestListNode.java – example Java class and its unit tests
Simple.java and testSimple.java – used in Discussions as examples of a class and JUnit tests for it.
List of assert methods that can be used in tests:
[http://junit.sourceforge.net/javadoc/org/junit/Assert.html](http://junit.sourceforge.net/javadoc/org/junit/Assert.html)
**Deliverables:**
Use the Report template (Pro5-ReportTemplate.doc) in Blackboard under Course Content->Projects->Project5 folder. The report must be submitted as an MS Word .doc. The name of the MS Word Report file shall be your_name_MSIT660_P6.doc. You must submit a separate file with your tests’ source code.
**Notes on pulling source code into eclipse**
1. Create a new Java project: File->New->Java Project (ex. MyProject5)
2. Click on “src” under your new project; right click and select import
3. Click on General->File System, then next and browse for where you have the file UTStringUtil.java, select it and click Finish
4. As an alternative you could create a new class StringUtils and copy/paste the file content into it.
5.
In your project, you will see the source file StringUtils.java under src directory.
**To add JUnit library to your Eclipse project:**
1. Right click on project and select Properties
2. Click on Java Build Path (left side list)
3. Click on “Add Library” button (right side)
4. Select JUnit and click next
5. Choose version 4 of Junit and click Finish
6. The JUnit library will now show under Libraries tab.
7. Click OK

**image1.png**
**## Project5-Instructions2.docx**
**Project 5**
**Unit Testing**
**Mission:**
You were asked by your manager to execute complete unit test (white box testing) for StringUtils Java class, written by a developer who suddenly left the team. You are provided the source code (StringUtils.java) and you are to write JUnit test cases for it. You are to assume that code description is correct for what each method is supposed to do and the code is supposed to match it.
**Objectives:**
Define, implement, and execute complete and thorough unit test on the given Java class (StringUtils.java).
**Outline of Steps:**
1. Fill out the Unit Test approach section in the template, explaining what unit test is all about and it’s most important criteria. Address all the questions completely and thoroughly.
2. Design tests for each method to meet 100% code coverage and reasonable data coverage. Describe these tests in the document using template format given. For this project you want to test methods against the code comments and the code itself. The code comments are assumed to be correct and the code may or may not be correct. Your goal is for your testcases to find defects in the code
3. Implement unit test cases in JUnit (e.g. StringUtilsTest.java)
4. Run the unit test cases and document the actual results in the report for each test case
5. Identify any defects you found running the JUnit and describe them in the report (using the template format) in section 2.
**Note:** You should find a few defects.
6. Submit both the report file and JUnit source code (java file).
7. All your tests must be in a single java file
Again, you should first identify and document in your report all the unit tests that should be created (using the example in report). That will give you partial credit – identifying the tests. Then you should implement those test cases in JUnit. Lastly you should run the test cases and document the actual results and defects you found.
**Resources:**
Proj5-MSIT660-GradingCriteria.doc – lists the grading criteria
Week 12-13 lecture charts – has unit test examples
ListNode.java and TestListNode.java – example Java class and its unit tests
Simple.java and testSimple.java – used in Discussions as examples of a class and JUnit tests for it.
List of assert methods that can be used in tests:
[http://junit.sourceforge.net/javadoc/org/junit/Assert.html](http://junit.sourceforge.net/javadoc/org/junit/Assert.html)
**Deliverables:**
Use the Report template (Pro5-ReportTemplate.doc) in Blackboard under Course Content->Projects->Project5 folder. The report must be submitted as an MS Word .doc. The name of the MS Word Report file shall be your_name_MSIT660_P6.doc. You must submit a separate file with your tests’ source code.
**Notes on pulling source code into eclipse**
1. Create a new Java project: File->New->Java Project (ex. MyProject5)
2. Click on “src” under your new project; right click and select import
3. Click on General->File System, then next and browse for where you have the file UTStringUtil.java, select it and click Finish
4. As an alternative you could create a new class StringUtils and copy/paste the file content into it.
5.
In your project, you will see the source file StringUtils.java under src directory.
**To add JUnit library to your Eclipse project:**
1. Right click on project and select Properties
2. Click on Java Build Path (left side list)
3. Click on “Add Library” button (right side)
4. Select JUnit and click next
5. Choose version 4 of Junit and click Finish
6. The JUnit library will now show under Libraries tab.
7. Click OK

**image1.png**
**Project5.docx**
This file is too large to display. [View in new window](https://www.sweetstudy.com/files/project5-docx-10531561)
**archive.zip**
This file is too large to display. [View in new window](https://www.sweetstudy.com/files/archive-zip-10531563)