TESTING CONVENTIONAL APPLICATIONS - CONTD. white-box UNIT TESTING Methods Performed by the Programmer who writes the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
TESTING CONVENTIONAL APPLICATIONS - CONTD. white-box UNIT TESTING Methods Performed by the Programmer who writes the "unit" What is considered as a "unit"? Code Inspection Code Walkthrough Metrics: Strategies STATIC UNIT TESTING Criteria - # of LOC reviewed per hour - # of CRs generated per KLOC - # of CRs generated per hour - # of hours spent on code review process Qotood Readiness Preparation Examination Re-work Validation Exit Code Review Steps Change Requests Report TOOLS FOR STATIC UNIT TESTING Bound checker/Memory leak detectors This tool can check for memory leaks, or writes to other memory location outside the data storage area of the application. Example: BoundsChecker (Devpartner by Borland) for C++ code https://www.microfocus.com/en- us/products/devpartner/overview?utm_medium=301&utm_source=borland.com Code auditor A source code analysis tool for discovering bugs, security breaches or violations of programming conventions. It generally looks for common vulnerabilities for specific programming languages. Example: SpotBugs in Eclipse for Java code (https://spotbugs.github.io/) String s1 = "Hello"; s1.concat(" World!"); System.out.println(s1); SPOTBUGS INSTALLATION Install SpotBugs plugin for Eclipse: https://marketplace.eclipse.org/content/spotbugs-eclipse-plugin Welcome Help Contents Search Show Contextual Help Show Active Keybindings... Tip of the Day & Tips and Tricks... Report Bug or Enhancement... Cheat Sheets... Eclipse User Storage Perform Setup Tasks... Check for Updates Install New Software... Eclipse Marketplace.. Comnipote Eclipse Marketplace Select solutions to install. Press Install Now to proceed with installation. Press the "more info" link to learn more about a solution. Search Recent Popular Favorites Installed Find: Q spotbugs ETTE 646 Giving loT an Edge All Markets C All Categories Installs: 116K (3,207 last month) 5 SpotBugs Eclipse plugin 3.1.5.r201806132012-cbbf0a5 SpotBugs is a defect detection tool for Java that uses static analysis to look for more than 400 bug patterns, such as null pointer dereferences, infinite... more info by Spot Bugs Team, LGPL 3 matches. Browse for more solutions. Go Install 6 SPOTBUGS ACTIVITY debug.msu.edu HelloWo Hellc Pm New Open Open With HelloWorld.java X 1 package debug.msu.edu; 2 import java.io.*; public class HelloWorld R 4 5 6 8 9 10 11 12 13 14 } Hello Import... Export... Open Type Hierarchy Show In References Declarations Copy Copy Qualified Name Paste X Delete Problems @ Javadoc Declaration Console X 3 Remove from Context Build Path Source Refactor public static void main(String[] args) throws IOException{ String s1 "Hello"; s1.concat(" World!"); System.out.println(s1); SpotBugs Refresh Assian Working Sets... } > HelloWorld (2) [Java Application] /Library/Java/JavaVirtual Machines/jdk-14.0.1 [HW F3 F4 CHS [HT %V Cblems Javadoc Declaration ated> HelloWorld (2) [Java Applicat EX TOXI public static void main String s1 "Hello" s1.concat(" World!" System.out.println } Find Bugs Clear Bug M SPOTBUGS ACTIVITY 3 import java.io.*; 4 5 public class HelloWorld { 8 13 14} public static void main(String[] args) throws IOException{ String s1 "Hello"; s1.concat(" World!"); System.out.println(s1); } 7 Problems @ Javadoc Declaration Console Bug Explorer Bug Info HelloWorld.java: 10 Navigation Return value of String.concat(String) ignored in debug.msu.edu.HelloWorld.main(String[]) Called method String.concat(String) Bug: Return value of String.concat(String) ignored in debug.msu.edu.HelloWc The return value of this method should be checked. One common cause of this the object. For example, in the following code fragment, String dateString = getHeaderField (name); dateString.trim(); the programmer seems to be thinking that the trim() method will update the Str function returns a new String value, which is being ignored here. The code sho String dateString = getHeaderField (name); dateString dateString.trim(); Rank: Scariest (3), confidence: High Pattern: RV_RETURN_VALUE_IGNORED Type: RV, Category: CORRECTNESS (Correctness) DYNAMIC UNIT TESTING Print DYNAMIC UNIT TESTING driver Sociable Tests Call Module to be tested 1 Often the tested unit relies on other units to fulfill its behavior Test cases Call and pass input parameters. Stub Test Driver Unit Under Test Acknowledge interface local data structures boundary conditions independent paths control flow, data flow Results Output parameters Call Acknowledge DYNAMIC UNIT TESTING-DRIVER, STUB A driver is a software module used to invoke a module under test and, often, provide test inputs, control and monitor execution, and report test results. (IEEE) Stub Print Solitary Tests stub Some unit testers prefer to isolate the tested unit unit under test A stub is a computer program statement substituting for the body of a software module that is or will be defined elsewhere. (IEEE) 10 (11) TOOLS FOR DYNAMIC UNIT TESTING - JAVA Code coverage / Test coverage analyzer These tools measure internal test coverage, often expressed in terms of control structure of the test object, and report the coverage metric. Example: ECLEmma in Eclipse for Java code. Eclipse Marketplace Eclipse Marketplace Select solutions to install. Press Install Now to proceed with installation. Press the "more info" link to learn more about a solution. Search Recent Popular Favorites Installed Find: Qeclemmal 980 } public class Person { X EclEmma Java Code Coverage 3.1.3 EclEmma is a free Java code coverage tool for Eclipse, available under the Eclipse Public License. It brings code coverage analysis directly into the Eclipse... more info by Mountainminds GmbH & Co. KG, EPL 2.0 Installs: 714K (3,564 last month) CODE COVERAGE IN JAVA - EXERCISE Giving loT an Edge } All Markets private String name; private String gender; public Person() { } } All Categories public void setName(String givenName) { name = givenName; } name="Not Disclosed"; gender="Not Disclosed"; public String getName() { return name; } public void setGender(String given Gender) { gender = givenGender; public String getGender() { return gender; Go Installed Unit under test 12 13 1 CODE COVERAGE IN JAVA - EXERCISE import java.io.*; import java.util.*; public class EclEmma Test{ 1 EclemmaTest 2 HelloWorld (2) 3 HelloWorld 3 2. # 6.0 ! Element 9 public static void main(String[] args) throws IOException { Scanner cin = new Scanner(System.in); System.out.print("How many persons? "); Coverage As Coverage Configurations... Organize Favorites... 10 } ECLEMMA - EXERCISE src } String num = cin.nextLine(); Writer wrt = new FileWriter("javatest.txt"); int loop = Integer.parseInt(num); for (int i=0; i JUNIT-A FRAMEWORK FOR UNIT TESTING JUnit: It is a framework for performing unit testing of Java programs. Typically a JUnit test is a method contained in a class which is only used for testing. The class is called a Test class. If you have several test classes, you can combine them into a test suite. Running a test suite will execute all test classes in that suite in the specified order. JUNIT - A FRAMEWORK FOR UNIT TESTING (CONTD.) JUnit 4-style: Create a 'normal' class and prepend a @Test annotation to the method. import org.junit.*; public class DummyTestB { @Test public void Sum() { int a 5; int b 10; int result a+b; assertEquals (15, result); AUTOMATED UNIT TESTING STEPS 1. Create an object of the class to be tested 2. Select a unit (e.g. method) to execute 3. Select values for the input parameters of the method 4. Compute the expected values to be returned by the method 5. Execute the selected methods on the created object using the selected input values 6. Verify the result of executing the method JUNIT TESTING. M public class Calc1 { public int Sum(int a, int b) { return (a+b); } EXERCISE } public int Minus(int a, int b) { if(ab) return (a-b); else return (b-a); Sample JUNIT Test @Test public void test() { } JUNIT - ASSERTION REFERENCE Important: Each Junit test method/function should cover only one testcase/scenario assert True(Boolean condition) https://junit.org/junit4/javadoc/4.8/org/junit/Assert.html assertFalse(Boolean condition) System.out.println("Test-1: running"); Calc1 c11= new Calc1(); assertEquals(10, c11.Sum(5, 5)); Class under development assertEquals(Object expected, Object actual) //same value assertEquals(int expected, int actual) assertEquals(double expected, double actual, double tolerance) assertSame(Object expected, Object actual) //same object assertNull(Object testobject) 19 20 TESTING CONVENTIONAL APPLICATIONS - CONTD. white-box UNIT TESTING Methods Performed by the Programmer who writes the "unit" What is considered as a "unit"? Code Inspection Code Walkthrough Metrics: Strategies STATIC UNIT TESTING Criteria - # of LOC reviewed per hour - # of CRs generated per KLOC - # of CRs generated per hour - # of hours spent on code review process Qotood Readiness Preparation Examination Re-work Validation Exit Code Review Steps Change Requests Report TOOLS FOR STATIC UNIT TESTING Bound checker/Memory leak detectors This tool can check for memory leaks, or writes to other memory location outside the data storage area of the application. Example: BoundsChecker (Devpartner by Borland) for C++ code https://www.microfocus.com/en- us/products/devpartner/overview?utm_medium=301&utm_source=borland.com Code auditor A source code analysis tool for discovering bugs, security breaches or violations of programming conventions. It generally looks for common vulnerabilities for specific programming languages. Example: SpotBugs in Eclipse for Java code (https://spotbugs.github.io/) String s1 = "Hello"; s1.concat(" World!"); System.out.println(s1); SPOTBUGS INSTALLATION Install SpotBugs plugin for Eclipse: https://marketplace.eclipse.org/content/spotbugs-eclipse-plugin Welcome Help Contents Search Show Contextual Help Show Active Keybindings... Tip of the Day & Tips and Tricks... Report Bug or Enhancement... Cheat Sheets... Eclipse User Storage Perform Setup Tasks... Check for Updates Install New Software... Eclipse Marketplace.. Comnipote Eclipse Marketplace Select solutions to install. Press Install Now to proceed with installation. Press the "more info" link to learn more about a solution. Search Recent Popular Favorites Installed Find: Q spotbugs ETTE 646 Giving loT an Edge All Markets C All Categories Installs: 116K (3,207 last month) 5 SpotBugs Eclipse plugin 3.1.5.r201806132012-cbbf0a5 SpotBugs is a defect detection tool for Java that uses static analysis to look for more than 400 bug patterns, such as null pointer dereferences, infinite... more info by Spot Bugs Team, LGPL 3 matches. Browse for more solutions. Go Install 6 SPOTBUGS ACTIVITY debug.msu.edu HelloWo Hellc Pm New Open Open With HelloWorld.java X 1 package debug.msu.edu; 2 import java.io.*; public class HelloWorld R 4 5 6 8 9 10 11 12 13 14 } Hello Import... Export... Open Type Hierarchy Show In References Declarations Copy Copy Qualified Name Paste X Delete Problems @ Javadoc Declaration Console X 3 Remove from Context Build Path Source Refactor public static void main(String[] args) throws IOException{ String s1 "Hello"; s1.concat(" World!"); System.out.println(s1); SpotBugs Refresh Assian Working Sets... } > HelloWorld (2) [Java Application] /Library/Java/JavaVirtual Machines/jdk-14.0.1 [HW F3 F4 CHS [HT %V Cblems Javadoc Declaration ated> HelloWorld (2) [Java Applicat EX TOXI public static void main String s1 "Hello" s1.concat(" World!" System.out.println } Find Bugs Clear Bug M SPOTBUGS ACTIVITY 3 import java.io.*; 4 5 public class HelloWorld { 8 13 14} public static void main(String[] args) throws IOException{ String s1 "Hello"; s1.concat(" World!"); System.out.println(s1); } 7 Problems @ Javadoc Declaration Console Bug Explorer Bug Info HelloWorld.java: 10 Navigation Return value of String.concat(String) ignored in debug.msu.edu.HelloWorld.main(String[]) Called method String.concat(String) Bug: Return value of String.concat(String) ignored in debug.msu.edu.HelloWc The return value of this method should be checked. One common cause of this the object. For example, in the following code fragment, String dateString = getHeaderField (name); dateString.trim(); the programmer seems to be thinking that the trim() method will update the Str function returns a new String value, which is being ignored here. The code sho String dateString = getHeaderField (name); dateString dateString.trim(); Rank: Scariest (3), confidence: High Pattern: RV_RETURN_VALUE_IGNORED Type: RV, Category: CORRECTNESS (Correctness) DYNAMIC UNIT TESTING Print DYNAMIC UNIT TESTING driver Sociable Tests Call Module to be tested 1 Often the tested unit relies on other units to fulfill its behavior Test cases Call and pass input parameters. Stub Test Driver Unit Under Test Acknowledge interface local data structures boundary conditions independent paths control flow, data flow Results Output parameters Call Acknowledge DYNAMIC UNIT TESTING-DRIVER, STUB A driver is a software module used to invoke a module under test and, often, provide test inputs, control and monitor execution, and report test results. (IEEE) Stub Print Solitary Tests stub Some unit testers prefer to isolate the tested unit unit under test A stub is a computer program statement substituting for the body of a software module that is or will be defined elsewhere. (IEEE) 10 (11) TOOLS FOR DYNAMIC UNIT TESTING - JAVA Code coverage / Test coverage analyzer These tools measure internal test coverage, often expressed in terms of control structure of the test object, and report the coverage metric. Example: ECLEmma in Eclipse for Java code. Eclipse Marketplace Eclipse Marketplace Select solutions to install. Press Install Now to proceed with installation. Press the "more info" link to learn more about a solution. Search Recent Popular Favorites Installed Find: Qeclemmal 980 } public class Person { X EclEmma Java Code Coverage 3.1.3 EclEmma is a free Java code coverage tool for Eclipse, available under the Eclipse Public License. It brings code coverage analysis directly into the Eclipse... more info by Mountainminds GmbH & Co. KG, EPL 2.0 Installs: 714K (3,564 last month) CODE COVERAGE IN JAVA - EXERCISE Giving loT an Edge } All Markets private String name; private String gender; public Person() { } } All Categories public void setName(String givenName) { name = givenName; } name="Not Disclosed"; gender="Not Disclosed"; public String getName() { return name; } public void setGender(String given Gender) { gender = givenGender; public String getGender() { return gender; Go Installed Unit under test 12 13 1 CODE COVERAGE IN JAVA - EXERCISE import java.io.*; import java.util.*; public class EclEmma Test{ 1 EclemmaTest 2 HelloWorld (2) 3 HelloWorld 3 2. # 6.0 ! Element 9 public static void main(String[] args) throws IOException { Scanner cin = new Scanner(System.in); System.out.print("How many persons? "); Coverage As Coverage Configurations... Organize Favorites... 10 } ECLEMMA - EXERCISE src } String num = cin.nextLine(); Writer wrt = new FileWriter("javatest.txt"); int loop = Integer.parseInt(num); for (int i=0; i JUNIT-A FRAMEWORK FOR UNIT TESTING JUnit: It is a framework for performing unit testing of Java programs. Typically a JUnit test is a method contained in a class which is only used for testing. The class is called a Test class. If you have several test classes, you can combine them into a test suite. Running a test suite will execute all test classes in that suite in the specified order. JUNIT - A FRAMEWORK FOR UNIT TESTING (CONTD.) JUnit 4-style: Create a 'normal' class and prepend a @Test annotation to the method. import org.junit.*; public class DummyTestB { @Test public void Sum() { int a 5; int b 10; int result a+b; assertEquals (15, result); AUTOMATED UNIT TESTING STEPS 1. Create an object of the class to be tested 2. Select a unit (e.g. method) to execute 3. Select values for the input parameters of the method 4. Compute the expected values to be returned by the method 5. Execute the selected methods on the created object using the selected input values 6. Verify the result of executing the method JUNIT TESTING. M public class Calc1 { public int Sum(int a, int b) { return (a+b); } EXERCISE } public int Minus(int a, int b) { if(ab) return (a-b); else return (b-a); Sample JUNIT Test @Test public void test() { } JUNIT - ASSERTION REFERENCE Important: Each Junit test method/function should cover only one testcase/scenario assert True(Boolean condition) https://junit.org/junit4/javadoc/4.8/org/junit/Assert.html assertFalse(Boolean condition) System.out.println("Test-1: running"); Calc1 c11= new Calc1(); assertEquals(10, c11.Sum(5, 5)); Class under development assertEquals(Object expected, Object actual) //same value assertEquals(int expected, int actual) assertEquals(double expected, double actual, double tolerance) assertSame(Object expected, Object actual) //same object assertNull(Object testobject) 19 20
Expert Answer:
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
need help entering sale oof land transaction in intuitproconnect On December 31, 2021, Anthony sold the inherited land from his uncle. The consideration was \( \$ 950,000 \) installment note plus the...
-
You and your friendly car dealer float a long string of closely spaced helium-filled balloons over his used-car lot. You secure the two ends of the long string of balloons to different points on the...
-
Solve the given systems of equations by either method of this section. 30P = 55-Q 19P + 140 + 32 = 0
-
When the Concepcions went to AT&T to get a phone, they were confused as to why they were paying money for the phone when it was advertised as being free. They had to pay sales tax on the full normal...
-
The Skyline Motel opened for business on May 1, 2014. Its trial balance before adjustment on May 31 is as follows. In addition to those accounts listed on the trial balance, the chart of accounts for...
-
Laverne owns 100% stock of the Pizza Bowl, Inc. (PB), which operates a classy combination bowling alley/pizza parlor. Her basis in the stock is $24,000. In its first year of existence, PB earned...
-
A contemporary observer remarked that the world war of 1914-1918 was the greatest moral, spiritual and physical catastrophe in the entire history of the English people Do you agree or disagree with...
-
I need some with this practice case, please. I rate The following is a waiting queue simulation model oriented towards service stations. The administration of a service station near a highway wants...
-
Our financial institution has been a leader in providing financial products and services to Canadians for over 100 years. As part of our commitment to meet the evolving needs of our customers, we are...
-
Discuss briefly the three inherent powers of the state, and for each power, give an example on how the state exercises them.
-
Your client traditionally provided free doughnuts and coffee to its employees every Friday morning to help boost morale. Under prior law, the cost of this event was 100 percent tax-deductible as a de...
-
If the price of sunscreen rises, with all other influences on buying plans remaining the same, does the demand for sunscreen change or does the quantity of sunscreen demanded change? A. The quantity...
-
Show graphically what is the effect of temperature on the rate of biological, normal, and explosive reactions.
-
Fill in each blank so that the resulting statement is true. 83 + 103 = ______ .
-
The town of Bellevue operates a private parking lot near the railroad station for the benefit of town residents. The guard on duty issues annual pre-numbered parking stickers to residents who submit...
-
Describe some of the basic database features available in SAP ERP for processing information pertaining to the sales business process.
-
Tom Hinkerton of Miami, Florida, has decided to set up a high- tech street- corner lemonade stand. He wants to use a notebook computer to record all sales in real time, and he also wants to track his...
-
A gene is a segment of DNA that contains the information to produce a functional product. The functional product of most genes is a. DNA. b. mRNA. c. a polypeptide. d. none of the above.
-
Which of the following is not a constituent of a cells proteome? a. An enzyme b. A cytoskeletal protein c. A transport protein in the plasma membrane d. An mRNA
-
The function of the genetic code is to a. promote transcription. b. specify the amino acids within a polypeptide. c. alter the sequence of DNA. d. do none of the above.
Debugging Teams Better Productivity Through Collaboration 1st Edition - ISBN: 1491932058 - Free Book
Study smarter with the SolutionInn App