Answered step by step
Verified Expert Solution
Question
1 Approved Answer
TESTING CONVENTIONAL APPLICATIONS - CONTD. white-box UNIT TESTING Methods Performed by the Programmer who writes the unit What is considered as a unit? Code
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started