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...
-
Net sales, net income, and total assets for Urbana Shipping, Inc., for a five-year period follow: 1. Compute trend percentages for each item for 2013 through 2016. Use 2012 as the base year and round...
-
During the first three quarters of FY 2018, Gabriel Armstrong at The Crooked Cup underwent a project to build an off-site prep bakery and storage warehouse to make an internal point of distribution...
-
The F statistic is the quotient of the sample ____________ . In Exercises 5 and 6, fill in each blank with the appropriate word or phrase.
-
The ANES in 2012 asked respondents to state their ages stored as AGE. a. Calculate the mean, variance, and standard deviation. b. Draw a histogram. c. Use the Empirical rule, if applicable, or...
-
Carla Corporation began operations in 2020 and reported pretax financial income of $237,000 for the year. Carla's tax depreciation exceeded its book depreciation by $44,000. Carla's tax rate for 2020...
-
McLennon Company had an Accounts Receivable balance of $320,000 and a credit balance in Allowance for Uncollectible Accounts of $16,700 at January 1, 2014. During the year, the company recorded the...
-
write the following system call in window and linux only system call names example create process in windows let ke fork() in linux 1. Process control end, abort load, execute 2. File management...
-
How would you rank-order the importance of analytic intelligence, practical intelligence, creative intelligence, or emotional intelligence for politicians? Explain why? Would this ranking be the same...
-
Discuss the evolution of NoSQL databases, tracing their origins from the need for handling unstructured and semi-structured data to the emergence of specialized databases like document-oriented,...
-
6 . Read the following information and answer questions that follow. ( 7 marks ) Tamapo s Trading account for the year ended 3 1 December 2 0 1 9 . Sales 2 4 0 , 0 0 0 . 0 0 Opening Stock 1 6 , 0 0...
-
Fields Company has two manufacturing departments, forming and painting. The company uses the weighted average method and it reports the following unit data for the Forming department. Units completed...
-
LearningTime, Inc.,isa large private, for-profittutoringcompany with80locationsand 900 employeesaround the country.The companyisacquiringasmaller competitor,Tutors-for-Kids,...
-
I. Convert the followings: a. 15 meters to feet b. 1200 ounces to milligrams c. 5 kg to ounces d. 50 miles to km e. 2655 ml to gallons f. 8 gallons to cubic centimeter g. 310 K to C h. 108 F to K II....
-
Presented below are income statements prepared on a LIFO and FIFO basis for Kenseth Company, which started operations on January 1, 2024. The company presently uses the LIFO method of pricing its...
-
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...
-
What is a post-mortem?
-
A __________ is another name for a project close-out meeting A. celebration B. post project C. final review D. post mortem
-
What advice about project closing is most useful to you? What other advice would you add?
Study smarter with the SolutionInn App