Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Unit Testing: Understanding the Concept, Phases, and Benefits, Study notes of Computer Science

An introduction to unit testing, explaining what it is, its purpose, phases, and benefits. It covers the concept of testing in general, the definition of a unit, and the advantages of unit testing. The document also discusses the importance of low coupling for effective testing and includes an example of conventional testing and its limitations.

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-yib
koofers-user-yib 🇺🇸

10 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download Unit Testing: Understanding the Concept, Phases, and Benefits and more Study notes Computer Science in PDF only on Docsity! 1 1 Unit Testing 2 Testing in General  Purpose – ?  Phases – ? 3 What Is Unit Testing?  Testing is ?  A unit is ?  Unit testing is ? 4 Why Unit Testing? 5 How to Do Unit Testing  Bottom up construction – Starts with classes that don’t depend on others. – Continue testing building on already tested classes.  Benefits – Avoid having to write (test) stubs. – When testing a module, rely only on tested modules. 6 Coupling  Coupling: the degree to which some component interacts with other components 2 7 Question  How does low coupling help testing?  How does high coupling hurt it? 8 Program to Test public final class IMath { /** * Returns an integer approximation * to the square root of x. */ public static int isqrt(int x) { int guess = 1; while (guess * guess < x) { guess++; } return guess; } } 9 Conventional Testing /** A class to test the class IMath. */ public class IMathTestNoJUnit { /** Runs the tests. */ public static void main(String[] args) { printTestResult(0); printTestResult(1); printTestResult(2); printTestResult(3); printTestResult(4); printTestResult(7); printTestResult(9); printTestResult(100); } private static void printTestResult(int arg) { System.out.print(“isqrt(“ + arg + “) ==> “); System.out.println(IMath.isqrt(arg)); } } 10 Conventional Test Output Isqrt(0) ==> 1 Isqrt(1) ==> 1 Isqrt(2) ==> 2 Isqrt(3) ==> 2 Isqrt(4) ==> 2 Isqrt(7) ==> 3 Isqrt(9) ==> 3 Isqrt(100) ==> 10  What does this say about the code? Is it right?  What’s the problem with this kind of test output? 11 Solution?  Automatic verification by testing program 12 Some Terminology  Definition – A test data (or case) for a method M is a pair of (o, args), where • o is not null and M can be sent to o, • args is a tuple of arguments that can be passed to M. – A test data, (o, args), for M succeeds iff o.M(args) behaves as expected. – A test data, (o, args), for M fails iff it does not behave as expected.  Question – Why should o not be null? – If M has a bug that is revealed by a test data, does that test data for M succeed or fail?
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved