CEN 5070 Software V&V Spring 2002 Testing 102 -- Internal Modules © 2001-2002, Dr. E.L. Jones.

Slides:



Advertisements
Similar presentations
Testing Relational Database
Advertisements

Testing Object Oriented Programs CSE 111 4/28/20151.
Key-word Driven Automation Framework Shiva Kumar Soumya Dalvi May 25, 2007.
Software Construction
Lucene Part3‏. Lucene High Level Infrastructure When you look at building your search solution, you often find that the process is split into two main.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
Jump to first page 1 System Design (Finalizing Design Specifications) Chapter 3d.
1 Software Testing and Quality Assurance Lecture 15 - Planning for Testing (Chapter 3, A Practical Guide to Testing Object- Oriented Software)
Ch1: File Systems and Databases Hachim Haddouti
SE 555 Software Requirements & Specification Requirements Validation.
Testing an individual module
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Recall The Team Skills Analyzing the Problem
Evolving an Elective Software Testing Course: Lessons Learned Edward L. Jones Florida A&M University Tallahassee, FL USA 3rd Workshop on Teaching Software.
Test Design Techniques
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
CS 8532: Adv. Software Eng. – Spring 2007 Dr. Hisham Haddad Tuesday Class will start momentarily. Please Stand By … CS 8532: Advanced Software.
UML - Development Process 1 Software Development Process Using UML (2)
CCSB223/SAD/CHAPTER141 Chapter 14 Implementing and Maintaining the System.
Ihr Logo Data Explorer - A data profiling tool. Your Logo Agenda  Introduction  Existing System  Limitations of Existing System  Proposed Solution.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 Software Testing (Part-II) Lecture Software Testing Software Testing is the process of finding the bugs in a software. It helps in Verifying and.
CPIS 357 Software Quality & Testing
Chapter 7 Structuring System Process Requirements
RUP Implementation and Testing
Winrunner Usage - Best Practices S.A.Christopher.
CEN Software V&V Spring 2002 Testing Application Forms © , Dr. E.L. Jones.
CEN 5070 – Software V&V BOUNDARY TESTING © , Dr. E.L. Jones.
Testing Basics of Testing Presented by: Vijay.C.G – Glister Tech.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
CEN 5070 – Software V&V Automation for Program Testing © , E.L. Jones.
Systems Analysis and Design in a Changing World, 3rd Edition
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 1.
CCSB223/SAD/CHAPTER131 Chapter 13 Designing the System Internals.
CEN 5070 – Software V&V What is Software Testing © , Dr. E.L. Jones.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
Chapter 8 Lecture 1 Software Testing. Program testing Testing is intended to show that a program does what it is intended to do and to discover program.
CIS 4932 Special Topics Software Testing Fall 2001 Practice -- Testing Forms © 2001, Dr. E.L. Jones.
Week 14 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Yazd University, Electrical and Computer Engineering Department Course Title: Advanced Software Engineering By: Mohammad Ali Zare Chahooki The Rational.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Testing Spring Applications Unit Testing.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Software Quality Assurance and Testing Fazal Rehman Shamil.
HNDIT23082 Lecture 09:Software Testing. Validations and Verification Validation and verification ( V & V ) is the name given to the checking and analysis.
Lecture 3 : Hard Systems Modelling UFCE8V-20-3 Information Systems Development SHAPE Hong Kong 2010/11.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
CEN 5070 – Software V&V Automation for Unit Testing © , E.L. Jones.
Software Testing.
SOFTWARE TESTING Date: 29-Dec-2016 By: Ram Karthick.
Programming Logic and Design Seventh Edition
7. Modular and structured design
Self Healing and Dynamic Construction Framework:
Chapter 8 – Software Testing
Florida A&M University
Stack Data Structure, Reverse Polish Notation, Homework 7
Applied Software Implementation & Testing
Verification and Validation Unit Testing
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
MATERI PL/SQL Procedures Functions Packages Database Triggers
Applying Use Cases (Chapters 25,26)
Applying Use Cases (Chapters 25,26)
Overview Activities from additional UP disciplines are needed to bring a system into being Implementation Testing Deployment Configuration and change management.
Presentation transcript:

CEN 5070 Software V&V Spring 2002 Testing Internal Modules © , Dr. E.L. Jones

1/2002Testing Internal Modules2 Purpose This lecture prepares the student to practice unit testing on a project by applying the concepts covered in the Software Unit Test Concepts course.

1/2002Testing Internal Modules3 Agenda Products & Deliverables Testing Classes What is Unit Testing? Testing Callable Modules Putting it All Together

1/2002Testing Internal Modules4 What is Unit Testing? Executing a software element to determine whether it meets its specification Executing a software element to discover defects or anomalies Inspecting software element code to discover defects or anomalies.

1/2002Testing Internal Modules5 What Is A Unit? Named software element with properties and behavior Separately invokable Performs single function Logically cohesive set of the above

1/2002Testing Internal Modules6 Examples of Units User-Visible software elements Fields on forms Buttons on forms Entire forms (reports) Program-Internal software elements Subprograms (procedures, functions, mains) Classes Databases

1/2002Testing Internal Modules7 Elementary Units Form Field Navigation Button Operation Button Database Field Stored Procedure Query Program Code Main Method Function Script

1/2002Testing Internal Modules8 Can A Unit Be Bigger? Yes, but beware of pitfalls Complex units are hard to test Repetition of tests more costly Tendency to focus on the easy part A composite unit (naturally related parts) A class = methods + data A form = data fields + action buttons One test script for hierarchical testing of parts, then whole

1/2002Testing Internal Modules9 Objective The practice of unit testing adds value to the development process by surfacing areas of incompleteness, inaccuracy or ambiguity. Extensive use of aids (checklists, worksheets) minimizes the effort but encourages thorough analysis.

1/2002Testing Internal Modules10 Agenda Products & Deliverables Testing Classes What is Unit Testing? Testing Callable Modules Putting It All Together

1/2002Testing Internal Modules11 Required Elements of Testing Practice S pecification for the software P rocess for designing test cases R epeatable process for designing, running and evaluating tests A ccountable artifacts of testing activities E conomical use of human, time and computing resources

1/2002Testing Internal Modules12 Recommended Practice Analysis Design Implementation Execution Evaluation Decision Table [Test Script, Driver] #Bugs Found Worksheet (Test Cases) Worksheet (Results) Specification, Code

1/2002Testing Internal Modules13 Products vs Deliverables A Product is an informal artifact from applying a testing process. belongs to the developer a physical form, not necessarily electronic A Deliverable is an artifact that attests to the application of the testing process belongs to the team an attesting signature required

1/2002Testing Internal Modules14 Product Templates Templates will be provided for these test products Black-box Schematic Decision table Unit test cases (functional, boundary) Unit test worksheets

1/2002Testing Internal Modules15 Agenda Products & Deliverables Testing Callable Subprograms/Methods What is Unit Testing? Testing Callable Modules Testing Database Procedures

1/2002Testing Internal Modules16 Testing Modules -- Overview Directly testing callable modules requires isolating the module and capturing the context in which it is called. Additional effort is required for this "code level" testing, but certain aspects can be automated, providing repeatability, efficiency and documentation.

1/2002Testing Internal Modules17 Testing Modules -- Drivers A test driver executes a unit with test case data and captures the results. Driver Test set Data External Effects Unit Arguments Results Test Set Results

1/2002Testing Internal Modules18 Implementing Test Drivers Complexity –Arguments/Results only –Special set-up required to execute unit –External effects capture/inquiry –Oracle announcing "PASS"/"FAIL" Major Benefits –Automated, repeatable test script –Documented evidence of testing –Universal design pattern

1/2002Testing Internal Modules19 Test Driver for Unit Pay Driver D_pay uses unit_environment E; { declare Hrs, Rate, expected; testcase_no = 0; open tdi_file("tdi-pay.txt"); open trs_file("trs-pay.txt"); while (more data in tdi_file) { read(tdi_file, Hrs, Rate); read(tdi_file, expected); testresult = pay(Hrs, Rate); write (trs_file, testcase_no++, Hrs, Rate, expected, testresult); }//while close tdi_file, trs_file; }//driver

1/2002Testing Internal Modules20 Test Driver Files (Pay) Test Data File File name: tdi-pay.txt Format: (test cases only) rate hours expected-pay File content: Note: No environment setup. Test Results File File name: trs-pay.txt Format: case# rate hours exp-pay act-pay File content: Note: Results file must be inspected for failures. Pass Fail Pass Test Script!!

1/2002Testing Internal Modules21 Testing Modules -- Drivers with Test Environment Set-Up The driver initializes the execution environment of the unit, and examines it after testing completes. External Effects Unit Driver Test set Data Arguments Results Test Set Results Environment Execution Environment Setup / Inquire

1/2002Testing Internal Modules22 Test Driver Files (Pay2) (Accumulates grand total of pay amounts) Pass Fail Pass Fail Test Data File File name: tdi-pay.txt Format: initial_pay_total final_pay_total {rate hours expected-pay} File content: Note: Environment setup = initialize global variable. Test Results File File name: trs-pay.txt Format: case# rate hours exp-pay act-pay env_init, env_exp, env_final File content: Note: Results file must be inspected for failures. Test Script!! Initial / Expected Grand Total

1/2002Testing Internal Modules23 Test Driver for Pay2 (Accumulates grand total of pay amounts) Driver D global total_pay; { open tdi_file ("tdi-pay2.txt"); open trs_file("trs-pay2.txt"); //Set up unit_environment E read (tdi_file, initial_tot, exp_tot); total_pay = initial_tot; testcase_no = 0; while (more data in tdi_file) { read (tdi_file, Hrs, Rate); read (tdi_file, expected); testresult = pay2(Hrs, Rate); write (trs_file, testcase_no++, Hrs, Rate, expected, testresult); }//while final_tot = total_pay; write(trs_file, initial_tot, exp_tot, final_tot); close tdi_file, trs_file; }//driver

1/2002Testing Internal Modules24 Unit Test Driver Design -- Test Environment Set-Up/Inquiry Driver D uses unit_environment E; { open tdi_file (filename); open trs_file (filename); //Set up unit_environment E read (tdi_file, E_initial, E_expect); E.set (E_initial); testcase_no = 0; while (more data in tdi_file) { read (tdi_file, testdata); read (tdi_file, expected); testresult = unit(testdata); write (trs_file, testcase_no++, testdata, expected, testresult); }//while E.get(E_final); write (trs_file, E_initial, E_expect, E_final); close tdi_file, trs_file; }//driver

1/2002Testing Internal Modules25 Your Turn -- Test Driver Design Unit GenPayroll(PayDate) computes pay for all employees who submitted time records (file "time.dat") for the previous week. All employees are hourly. Employee IDs, pay rates, and YTD earnings are stored in the Employee database ("emp.db"). GenPayroll calls unit Pay (Hours, Rate) to compute gross pay. Next, GenPayroll deducts a flat 10%, then writes PayDate, EmployeeID, Hours, Rate, GrossPay, Deductions, and NetPay to the Payroll Register (file "payreg.dat"). Finally, GenPayroll updates YTD-Earning for the employee Design the test driver for GenPayroll. Focus on (1) required set- up; (2) data preparation; (3) test execution; (4) verification of results.

1/2002Testing Internal Modules26 Your Turn -- Test Driver Design Driver PayDate GenPayroll Pay Rate Hours GrossPay file "time.dat" database "emp.db" file "payreg.dat" Verification Set-Up

1/2002Testing Internal Modules27 Agenda Products & Deliverables Testing Classes What is Unit Testing? Testing Callable Modules -- DB Proc Putting It All Together

1/2002Testing Internal Modules28 Testing DB Procedures -- Overview Since the database plays a central role in a system, database procedures should be tested carefully. Automating this testing permits thorough testing and efficient verification via database queries. Trusted database code is a candidate for reuse.

1/2002Testing Internal Modules29 Testing DB Procedures -- Process Set-Up Initialize DB to baseline (or error) state Run Test Script (manual/automated) Run Verification Script (manual/auto) Verify queries, updates A test driver can combine the test and verification scripts into a single, comprehensive test.

1/2002Testing Internal Modules30 Testing Callable Units -- Summary A test driver is a reusable design pattern. Test drivers give code-level visibility into the behavior of units, while documenting the testing process. A unit driver can be used for indirect testing of lower level modules. The unit test driver can be extended to test complex units (classes).

1/2002Testing Internal Modules31 Agenda Products & Deliverables Testing Classes What is Unit Testing? Testing Callable Modules Putting It All Together

1/2002Testing Internal Modules32 Testing Classes -- Overview A class is a collection of elementary units (methods) sharing an execution context. As with forms, testing a class requires unit testing of its methods along with an "integration" test of the overall semantics of the class. The approach for unit testing is extended for classes.

1/2002Testing Internal Modules33 Testing Classes -- Drivers (Black-Box) Class Test Driver Method Args /Results Test set Data Test Set Results Class Class-state Method(s)

1/2002Testing Internal Modules34 Example -- Stack Class class Stack { public: Stack(); void push(int n); int pop(); int top(); bool empty(); private: int Size; int Top; int Values[100]; }; Notes: (1) Class state -- variables Size, Top and the first 'Size' values in array Values. (2) Methods push and pop modify class state; top and empty inquire about the state. (3) Stack does not require any test environment of its own. (4) Class state HIDDEN from test, i.e., black box.

1/2002Testing Internal Modules35 Test Driver Files (Stack class) Test Data File (tdi-stack.txt) File content: true Note: No test environment setup. Methods: 1-push, 2-pop, 3-top, 4-empty Test Results File (trs-stack.txt) File content: Note: Results file must be inspected for pass/fails. --- Top should be Push. --- Pop, should be Stack should be empty. Fail Pass

1/2002Testing Internal Modules36 Class Test Driver Design Driver dC uses class C { c = new (C); testcase_no = 0; open tdi_file("tdi_stack.txt"); open trs_file("trs_stack.txt"); while (more data in tdi_file) { op = read(tdi_file); switch (op) { case 1: //Push. read(tdi_file, value); c.push(value); write(trs_file, testcase_no, 1, value); break; case 2: //Pop. read(tdi_file, expect); value = c.pop(); write(trs_file, testcase_no, 2, expect, value); break;

1/2002Testing Internal Modules37 Class Test Driver Design … default: } //switch }//while close tdi_file, trs_file; }//class-driver case 3: //Top. read(tdi_file, expect); value = c.top(); write(trs_file, testcase_no, 3, expect, value); break; case 4: //Empty. read(tdi_file, expect); value = c.empty(); write(trs_file, testcase_no, 4, expect, value); break;

1/2002Testing Internal Modules38 Implementing Class Test Drivers Interactive vs Batch (files) Extend Unit Driver –switch to handle multiple methods –Method-specific test cases –Method interactions tested –All results stored in common results file Major Benefits -- comprehensive driver –Automated, repeatable, documented –Minimized set-up

1/2002Testing Internal Modules39 Class Test Driver -- Summary Data Driven -- flexible, extensible Varying levels of detail –black-box (method calls, no class state) –clear-box (class state, advanced topic) –global effects (test environment) A driver is a reusable pattern for testing.

1/2002Testing Internal Modules40 Clear-Box Class Testing -- Drivers Use Internal State External Test Env Class Test Driver Method Args /Results Test set Data Test Set Results Setup / Inquire Internal Test Env Class Test Env Class-state Method(s) Class State Setup/Inquire

1/2002Testing Internal Modules41 Example -- Stack Class class Stack { public: Stack(); void push(int n); int pop(); int top(); bool empty(); void SetState(int,int,int[]); void GetState(int &,int &,int[]); private: int Size; int Top; int Values[100]; }; Notes: (1) Class state -- variables Size, Top and the first 'Size' values in array Values. (2) Methods push and pop modify class state; top and empty inquire about the state. (3) "Hooks" can be created to set and retrieve the class state. (4) Stack does not require any test environment of its own.

1/2002Testing Internal Modules42 Class Test Driver Design Driver dC uses Test_Env T; uses class C { // Set up external environment // c = new (C); testcase_no = 0; open tdi_file (filename); open trs_file (filename) case -4: //Set test env// read(tdi_file. t_env); T.setenv(t_env); break; case -3: //Get test env// T.getenv(t_env); write(trs_file, t_env); break; case -2: //Set class state// read(tdi_file, c_state); c.setstate(c_state); break;

1/2002Testing Internal Modules43 Class Test Driver Design // If the internal state of the class // must be set or checked, a (-2) // precedes case "m", and a (-1) // follows case "m". // Remaining methods … // default: } //switch }//while close tdi_file, trs_file; }//driver case -1: //Get class state. c.getstate(c_state); write(trs_file, c_state); break; case m: // test class method #m. read(tdi_file, args); read(tdi_file, expect); result = method(args); write (trs_file, testcase_no++, args, expect, result); break;

1/2002Testing Internal Modules44 Agenda Products & Deliverables Testing Classes What is Unit Testing? Testing Callable Modules Putting It All Together

1/2002Testing Internal Modules45 Putting It Together Test design is the central thing Test scripts define the sequence of test actions -- a repeatable process Test drivers automate test scripts and produce test documentation Automation is reusable!

1/2002Testing Internal Modules46 CONCLUSION Unit testing lays the foundation for software testing. The techniques covered in this class extend from simple to complex units and, as we will see, to integration testing. Worksheets and templates facilitate the process while guiding the tester through a systematic design process.

1/2002Testing Internal Modules47 SOLUTIONS TO EXERCISES

1/2002Testing Internal Modules48 Unit Test Driver Design -- Global Pre/Post Conditions (pattern) Driver D uses unit_environment E; { open testdata_file(filename); open testresults_file(filename); // Set up unit_environment E\ read (testdata_file, E_initial); E.set (E_initial ); testcase_no = 0; while (more data in testdata_file) { read(testdata_file, testdata); read(testdata_file, expected); testresult = unit(testdata); write (testresults_file, testcase_no++, testdata, expected, testresult); }//while E.get(E_final); write(testresults_file, E_initial, E_expect, E_final) close testdata_file, testresults_file; }//driver