Introduction to Unit Testing Jun-Ru Chang 2012/05/03.

Slides:



Advertisements
Similar presentations
Object Oriented Analysis And Design-IT0207 iiI Semester
Advertisements

Software Testing. Quality is Hard to Pin Down Concise, clear definition is elusive Not easily quantifiable Many things to many people You'll know it when.
Test Yaodong Bi.
Test process essentials Riitta Viitamäki,
Testing and Quality Assurance
What is Unit Testing? How TDD Works? Tsvyatko Konov Telerik Corporation
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
Informatics 43 – April 30, What is a test case? An input to a system, and the correct output. An “input” may be complex. Example: – What is an input.
JUnit. What is unit testing? A unit is the smallest testable part of an application. A unit test automatically verifies the correctness of the unit. There.
Program Testing Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Outline Types of errors Component Testing Testing Strategy
Software Testing Prasad G.
Automated Testing Nathan Weiss April 23, Overview History of Testing Advantages to Automated Testing Types of Automated Testing Automated Testing.
Introduction to Software Testing
BY RAJESWARI S SOFTWARE TESTING. INTRODUCTION Software testing is the process of testing the software product. Effective software testing will contribute.
TDD,BDD and Unit Testing in Ruby
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Testing. Definition From the dictionary- the means by which the presence, quality, or genuineness of anything is determined; a means of trial. For software.
Software Testing. Definition To test a program is to try to make it fail.
Software Testing CS 121 “Ordering Chaos” “Mike” Michael A. Erlinger
CMSC 345 Fall 2000 Unit Testing. The testing process.
Software Engineering Chapter 23 Software Testing Ku-Yaw Chang Assistant Professor Department of Computer Science and Information.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Testing in Extreme Programming
1 Software testing. 2 Testing Objectives Testing is a process of executing a program with the intent of finding an error. A good test case is in that.
Testing Basics of Testing Presented by: Vijay.C.G – Glister Tech.
Testing Workflow In the Unified Process and Agile/Scrum processes.
Software Testing. 2 CMSC 345, Version 4/12 Topics The testing process  unit testing  integration and system testing  acceptance testing Test case planning.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
COMP 121 Week 1: Testing and Debugging. Testing Program testing can be used to show the presence of bugs, but never to show their absence! ~ Edsger Dijkstra.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
White-box Testing.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Testing, The Ugly Stepchild of Software Development Better Living through Software Testing Chris Berry – Feb 21, 2000 Chris Berry
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
JUnit Don Braffitt Updated: 10-Jun-2011.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 11, Testing.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
Software Testing. System/Software Testing Error detection and removal determine level of reliability well-planned procedure - Test Cases done by independent.
Software Quality Assurance and Testing Fazal Rehman Shamil.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Dynamic Testing.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Jason I. Hong CS169 - Software Engineering, Fall 1998 Testing Strategies.
Testing JUnit Testing. Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes.
Test Plans Test Driven Development – Unit test plan first Code coverage Automated Regression built as you go Debug is easier Serves as system doc – Still.
Testing. Aspects of Quality Software Flexibility Extensibility Correctness Robustness Reliability Safety Usability.
Software Testing.
Unit Testing.
Software Testing.
Smalltalk Testing - SUnit
Test Driven Development
Software engineering – 1
Chapter 13 & 14 Software Testing Strategies and Techniques
Introduction to Software Testing
Software Testing (Lecture 11-a)
Testing and Test-Driven Development CSC 4700 Software Engineering
Informatics 43 – April 28, 2016.
CS 240 – Advanced Programming Concepts
Java & Testing.
CSE 1020:Software Development
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

Introduction to Unit Testing Jun-Ru Chang 2012/05/03

Introduction Software is a collection of computer programs and related data that provide the instructions for telling a computer what to do and how to do it.

What is Bug What is Software Testing –Software testing is an action which attempt to find bugs either manually or through automation tools.

How to Make Bug 4 BUG Software specifications keep constantly changing Software design is rushed or changed Software complexity or poor documentation Lack of proper skill set in programmers Time pressure

How to Make Bug (cont.) 2, 3: Unimplemented spec 1, 2: Unfulfilled Needs 4, 7: Unexpected Behavior 6, 7: Undesired Behavior

Cost of Fixing Defects Cost to fix a defect Time detected RequirementsArchitectureConstruction System test Post-release Time introduced Requirements1x3x5-10x10x10-100x Architecture-1x10x15x25-100x Construction--1x10x10-25x source: McConnell, Steve (2004). Code Complete (2nd ed.). Microsoft Press. pp. 29. ISBN The earlier a defect is found, the cheaper it is to fix it.

Software testing Dijkstra’s criticism, “Program testing can be used to show the presence of bugs, but never to show their absence” –Only as good as the test data selected –Compared to “expected output”

Software testing (cont.) Methodologies –Black box testing –White box testing Myths about testing –Bugs are simple to remove –A bug is caused in exactly one module –Most bugs will be caught by the compiler –Bug fixes always make the program better Imperfect debug SpecifiedProgrammed Test case

Software testing (cont.) Test case –“Bugs lurk in corners and congregate at boundaries…” –The pesticide paradox

Boundary Value Analysis Boundary value analysis –Input data –Loop iteration –Output fields

Boundary Value Analysis (cont.) Robustness boundary value analysis Worst case boundary value analysis Robust worst case boundary value analysis

Boundary Value Analysis (cont.) Hierarchy –Boundary value testing: 4n+1 –Robustness: 6n+1 –Worst case: 5 n –Robust worst case: 7 n

White-box Testing

Software testing (cont.) Complete testing –At the end of testing, you know there are no remaining unknown bugs. IMPOSSIBLE Can’t test all inputs, timing, and paths

Software testing (cont.) When to stop testing? –Cost –Coverage strategy

Software testing (cont.) Type of software testing –Unit testing –Integration testing –Function testing –System testing –Load testing –Stress testing –Performance testing –Regression testing –…etc.

Regression testing Seek to uncover new errors in existing functionality after changes have been made to a system, such as functional enhancements, patches or configuration changes.

Extreme Programming

Test-Driven Development (TDD) TDD is an evolutionary approach to development which combines test-first development where you write a test before you write just enough production code to fulfill that test and refactoring.

Unit Testing Framework Kent Beck –Simple Smalltalk Testing –JUnit CUnit, NUnit, C++Unit... –XUnit

CUnit CUnit is a lightweight system for writing, administering, and running unit tests in C. It provides C programmers a basic testing functionality with a flexible variety of user interfaces.

CUnit (cont.) CU_initialize_registry(): Initialize the test registry CU_add_suite(): Add suite to the test registry CU_add_test(): Add tests to the suites CU_console_run_tests(): Run tests CU_cleanup_registry(): Cleanup the test registry CU_ASSERT(int expression)

CUnit (cont.) if(CUE_SUCCESS != CU_initialize_registry()){ return CU_get_error(); } end: CU_cleanup_registry(); return CU_get_error();

CUnit (cont.) CU_pSuite addSuite = CU_add_suite("add_1", init_add_1, clean_add_1); void testadd1(){ CU_ASSERT( 0 == add(0, 0)); CU_ASSERT( 2 == add(2, 0)); } void testadd2(){ CU_ASSERT(-1 == add(0, -1)); CU_ASSERT(-2 == add(-1, -2)); }

CUnit (cont.) if(CU_add_test(addSuite, "correct suite", testadd1) == NULL || CU_add_test(addSuite, "fail suite", testadd2) == NULL) goto end; CU_basic_run_tests();

CUnit (cont.) Compile & execution –gcc add.c tc1.c -lcunit –./a.exe Official website:

CUnit (cont.) $./a.exe CUnit - A unit testing framework for C - Version init Suite add_1, Test fail suite had failures: 1. tc1.c: == add(-1, -2)clean Run Summary: Type Total Ran Passed Failed Inactive suites 1 1 n/a 0 0 tests asserts n/a Elapsed time = seconds execute init_add_1 execute clean_add_1 execution time issue code

Setup cygwin – –choose download add ftp://ftp.ntu.edu.tw/cygwin –select package gcc: Devel -> gcc-core: C compiler cunit: Libs -> CUnit –C:\cygwin\home\USER_NAME

Practice Fibonacci Sequence –F(0) = 1, F(1) =1 –F(m) = F(m-1) + F(m-2), m>=0

Practice 4 Basic Arithmetic Operations –Integer