Principles of Software Construction: Objects, Design, and...

100
1 15-214 School of Computer Science Principles of Software Construction: Objects, Design, and Concurrency (Part 2: Designing (Sub-)Systems) More Analysis for Functional Correctness Christian Kästner Bogdan Vasilescu

Transcript of Principles of Software Construction: Objects, Design, and...

Page 1: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

115-214

SchoolofComputerScience

PrinciplesofSoftwareConstruction:Objects,Design,andConcurrency(Part2:Designing(Sub-)Systems)

MoreAnalysisforFunctionalCorrectness

ChristianKästner BogdanVasilescu

Page 2: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

215-214

Administrativa

• Reviewsessionsstartedyesterday– Therearestillmanyslotsforreviewsessions– Onceyousignedup,pleaselookuptheplaceofthereviewsessioninthecoursecalendarhttps://www.cs.cmu.edu/~ckaestne/15214/s2017/

– Ifthereareofficehoursandreviewsessionsinparallel,thesignupisforthereviewsession

• HomeworkisdueonThursday.

Page 3: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

315-214

LearningGoals

• Basicunderstandingofrefactoring• Integratingunittestingintothedesignprocess• Understandingandapplyingcoveragemetricstoapproximatetestsuitequality;awarenessofthelimitations

• Basicunderstandingofthemechanismsandlimitationsofstaticanalysistools

• Characterizingassurancetechniquesintermsofsoundnessandcompleteness

Page 4: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

415-214

Correctness?

Page 5: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

515-214

SoftwareErrors• Functionalerrors• Performanceerrors• Deadlock• Raceconditions• Boundaryerrors• Bufferoverflow• Integrationerrors• Usabilityerrors• Robustnesserrors• Loaderrors

• Designdefects• Versioningand

configurationerrors• Hardwareerrors• Statemanagementerrors• Metadataerrors• Error-handlingerrors• Userinterfaceerrors• APIusageerrors• …

Page 6: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

615-214

SoftwareErrors• Functionalerrors• Performanceerrors• Deadlock• Raceconditions• Boundaryerrors• Bufferoverflow• Integrationerrors• Usabilityerrors• Robustnesserrors• Loaderrors

• Designdefects• Versioningand

configurationerrors• Hardwareerrors• Statemanagementerrors• Metadataerrors• Error-handlingerrors• Userinterfaceerrors• APIusageerrors• …

Page 7: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

715-214

CODESMELLS

Page 8: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

815-214

BadSmells->DesignDefects

• BadSmellsindicatethatyourcodeisripeforrefactoring

• Refactoringisabouthowtochangecodebyapplyingrefactorings

• Badsmellsareaboutwhentomodifyit

Page 9: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

915-214

BadSmells:Classification

• Topcrime:codeduplication• Class/methodorganization

– Largeclass,LongMethod,LongParameterList,LazyClass,DataClass,...

• Lackofloosecouplingorcohesion– InappropriateIntimacy,FeatureEnvy,DataClumps,...

• Toomuchortoolittledelegation– MessageChains,MiddleMan,...

• NonObject-Orientedcontrolordatastructures– SwitchStatements,PrimitiveObsession,...

• Other:Comments

Page 10: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1015-214

Codeduplication(1)

code

code

code

code

Class

Method 1

Method 2

Method 3

code

Class

Method 1

Method 2

Method X

MethodX();

Method 3MethodX();

MethodX();MethodX();

• Extract method

• Rename method

Page 11: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1115-214

Codeduplication(2)

code

Subclass A

Method codeMethod

Subclass BClass

Sameexpressionintwosiblingclasses:

• Samecode:Extractmethod+Pullupfield

• Similarcode:Extractmethod+FormTemplateMethod

• Differentalgorithm:Substitutealgorithm

Page 12: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1215-214

Codeduplication(3)

code

ClassA

MethodA codeMethodB

ClassB

Page 13: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1315-214

Codeduplication(3)ClassA

MethodA MethodB

ClassB

Sameexpressionintwounrelatedclasses:

• Extractclass

• Ifthemethodreallybelongsinoneofthetwoclasses,keepitthereandinvokeitfromtheotherclass

code

ClassX

MethodX

ClassX.MethodX(); ClassX.MethodX();

Page 14: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1415-214

Longmethod//700LOCpublic boolean foo() {

try {synchronized () {

if () {} else {}for () {

if () {if () {

if () {if ()?{

if () {for () {}

}}

} else {if () {

for () {if () {} else {}if () {} else {

if () {}

}if () {

if () {if () {

for () {}

}}

} else {}

}} else {

Source: http://thedailywtf.com/Articles/Coding-Like-the-Tour-de-France.aspx

• Rememberthis?

Page 15: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1515-214

Refactoringalongmethodvoid printOwing() {

Enumeration e = _orders.elements();double outstanding = 0.0;// Print banner System.out.println(“******************“);System.out.println(“***** Customer *****“); System.out.println(“******************“);// Calculate outstandingWhile (e.hasMoreElements()) {

Order each = (Order) e.nextElement(); outstanding += each.getAmount();

} // Print details System.out.println(“name: “ + _name); System.out.println(“amount” + outstanding);

}

Page 16: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1615-214

Refactoringalongmethodvoid printOwing() {

Enumeration e = _orders.elements();double outstanding = 0.0;// Print banner System.out.println(“******************“);System.out.println(“***** Customer *****“); System.out.println(“******************“);// Calculate outstandingWhile (e.hasMoreElements()) {

Order each = (Order) e.nextElement(); outstanding += each.getAmount();

} // Print details System.out.println(“name: “ + _name); System.out.println(“amount” + outstanding);

}

Page 17: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1715-214

Refactoringalongmethodvoid printOwing() {

Enumeration e = _orders.elements();double outstanding = 0.0;

printBanner();

// Calculate outstandingWhile (e.hasMoreElements()) {

Order each = (Order) e.nextElement(); outstanding += each.getAmount();

} // Print details System.out.println(“name: “ + _name); System.out.println(“amount” + outstanding);

}

void printBanner(){System.out.println(“******************“);System.out.println(“***** Customer *****“); System.out.println(“******************“);

}

Extractmethod

CompileandtesttoseewhetherI'vebrokenanything

Page 18: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1815-214

Refactoringalongmethodvoid printOwing() {

Enumeration e = _orders.elements();double outstanding = 0.0;

printBanner();

// Calculate outstandingWhile (e.hasMoreElements()) {

Order each = (Order) e.nextElement(); outstanding += each.getAmount();

} // Print details System.out.println(“name: “ + _name); System.out.println(“amount” + outstanding);

} void printBanner(){…}

Page 19: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

1915-214

Refactoringalongmethodvoid printOwing() {

Enumeration e = _orders.elements();double outstanding = 0.0;

printBanner();

// Calculate outstandingWhile (e.hasMoreElements()) {

Order each = (Order) e.nextElement(); outstanding += each.getAmount();

} printDetails(outstanding);

}void printBanner(){…}void printDetails(outstanding){

System.out.println(“name: “ + _name); System.out.println(“amount” + outstanding);

}

Extractmethodusinglocalvariables

CompileandtesttoseewhetherI'vebrokenanything

Page 20: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2015-214

Refactoringalongmethodvoid printOwing() {

Enumeration e = _orders.elements();double outstanding = 0.0;

printBanner();

// Calculate outstandingWhile (e.hasMoreElements()) {

Order each = (Order) e.nextElement(); outstanding += each.getAmount();

} printDetails(outstanding);

}void printBanner(){…}void printDetails(outstanding){

System.out.println(“name: “ + _name); System.out.println(“amount” + outstanding);

}

Page 21: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2115-214

Refactoringalongmethodvoid printOwing() {

Enumeration e = _orders.elements();double outstanding = getOutstanding(); printBanner(); printDetails(outstanding);

}void printBanner(){…}void printDetails(outstanding){…}

double getOutstanding() { Enumeration e = _orders.elements();double result = 0.0; While (e.hasMoreElements()) {

Order each = (Order) e.nextElement(); result += each.getAmount();

} return result;

}

Extractmethodreassigningalocalvariable

CompileandtesttoseewhetherI'vebrokenanything

Page 22: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2215-214

ManyMoreBadSmells

• Topcrime:codeduplication• Class/methodorganization

– Largeclass,LongMethod,LongParameterList,LazyClass,DataClass,...

• Lackofloosecouplingorcohesion– InappropriateIntimacy,FeatureEnvy,DataClumps,...

• Toomuchortoolittledelegation– MessageChains,MiddleMan,...

• NonObject-Orientedcontrolordatastructures– SwitchStatements,PrimitiveObsession,...

• Other:Comments

Page 23: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2315-214

BACKTOFUNCTIONALCORRECTNESS

Page 24: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2415-214

Reminder:FunctionalCorrectness

• Thecompilerensuresthatthetypesarecorrect(typechecking)– Prevents“MethodNotFound”and“CannotaddBooleantoInt”errorsatruntime

• Staticanalysistools(e.g.,FindBugs)recognizecertaincommonproblems– WarnsonpossibleNullPointerExceptions orforgettingtoclosefiles

• Howtoensurefunctionalcorrectnessofcontractsbeyond?

Page 25: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2515-214

FormalVerification

• Provingthecorrectnessofanimplementationwithrespecttoaformalspecification,usingformalmethodsofmathematics.

• Formallyprovethatallpossibleexecutionsofanimplementationfulfillthespecification

• Manualeffort;partialautomation;notautomaticallydecidable

Page 26: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2615-214

Testing

• Executingtheprogramwithselectedinputsinacontrolledenvironment(dynamicanalysis)

• Goals:– Revealbugs(maingoal)– Assessquality(hardtoquantify)– Clarifythespecification,documentation– Verifycontracts

"Testing shows the presence, not the absence of bugs

Edsger W. Dijkstra 1969

Page 27: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2715-214

TestingDecisions• Whotests?

– Developers– OtherDevelopers– SeparateQualityAssuranceTeam– Customers

• Whentotest?– Beforedevelopment– Duringdevelopment– Aftermilestones– Beforeshipping

• Whentostoptesting?

(More in 15-313)

Page 28: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2815-214

TEST-DRIVENDEVELOPMENT

Page 29: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

2915-214

Test Driven Development

(CC BY-SA 3.0) Excirial

• Testsfirst!• Popular

agiletechnique• Writetestsas

specificationsbeforecode• Neverwritecodewithout

afailingtest

Page 30: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3015-214

Mobprogramming

• WriteaprogramusingTDDthattakesasinputacharacterA..Zandprintsadiamondpattern:

A AB BA

AB B

C C CB BA

Input:A Input:B Input:C

Page 31: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3115-214

Test Driven Development• Testsfirst!• Popular

agiletechnique• Writetestsas

specificationsbeforecode• Neverwritecodewithout

afailingtest• Claims:

• Designapproachtowardtestabledesign• Thinkaboutinterfacesfirst• Avoidwritingunneededcode• Higherproductquality(e.g.bettercode,lessdefects)• Highertestsuitequality• Higheroverallproductivity

(CC BY-SA 3.0) Excirial

Page 32: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3215-214

TESTCOVERAGE

Page 33: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3315-214

Howmuchtesting?

• Yougenerallycannottestallinputs– toomany,usuallyinfinite

• Butwhenitworks,exhaustivetestingisbest!

• Whentostoptesting?– inpractice,whenyourunoutofmoney

Page 34: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3415-214

Whatmakesagoodtestsuite?

• Provideshighconfidencethatcodeiscorrect• Short,clear,andnon-repetitious

– Moredifficultfortestsuitesthanregularcode– Realistically,testsuiteswilllookworse

• Canbefuntowriteifapproachedinthisspirit

Page 35: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3515-214

• Alsoknowasfuzztesting,torturetesting• Try“random”inputs,asmanyasyoucan

– Chooseinputstotickleinterestingcases– Knowledgeofimplementationhelpshere

• Seedrandomnumbergeneratorsotestsrepeatable• Successfulinsomedomains(parsers,networkissues,…)

– But,manytestsexecutesimilarpaths– But,oftenfindsonlysuperficialerrors

Blackbox:RandomInputsNextbestthingtoexhaustivetesting

Page 36: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3615-214

Blackbox testing

Blackbox:CoveringSpecifications

• Lookingatspecifications,notcode:

• Testrepresentativecase• Testboundarycondition• Testexceptionconditions• (Testinvalidcase)

Page 37: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3715-214

TextualSpecificationpublic int read(byte[] b, int off, int len) throws IOException

§ Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

§ If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

§ The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

§ In every case, elements b[0] through b[off] and elements b[off+len] through b[b.length-1] are unaffected.

• Throws:§ IOException - If the first byte cannot be read for any reason other than end of file, or if

the input stream has been closed, or if some other I/O error occurs.§ NullPointerException - If b is null.§ IndexOutOfBoundsException - If off is negative, len is negative, or len is greater

than b.length - off

Page 38: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3815-214

StructuralAnalysisofSystemunderTest

– Organizedaccordingtoprogramdecisionstructure

public static int binsrch (int[] a, int key) {

int low = 0;int high = a.length - 1;

while (true) {

if ( low > high ) return -(low+1);

int mid = (low+high) / 2;

if ( a[mid] < key ) low = mid + 1;else if ( a[mid] > key ) high = mid - 1;else return mid;

}}

Whitebox testing

Page 39: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

3915-214

StructuralAnalysisofSystemunderTest

– Organizedaccordingtoprogramdecisionstructure

public static int binsrch (int[] a, int key) {

int low = 0;int high = a.length - 1;

while (true) {

if ( low > high ) return -(low+1);

int mid = (low+high) / 2;

if ( a[mid] < key ) low = mid + 1;else if ( a[mid] > key ) high = mid - 1;else return mid;

}}

Whitebox testing

Will this statement get executed in a test?

Does it return the correct result?

Page 40: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4015-214

StructuralAnalysisofSystemunderTest

– Organizedaccordingtoprogramdecisionstructure

public static int binsrch (int[] a, int key) {

int low = 0;int high = a.length - 1;

while (true) {

if ( low > high ) return -(low+1);

int mid = (low+high) / 2;

if ( a[mid] < key ) low = mid + 1;else if ( a[mid] > key ) high = mid - 1;else return mid;

}}

Whitebox testing

Could this array index be out of bounds?

Will this statement get executed in a test?

Does it return the correct result?

Page 41: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4115-214

StructuralAnalysisofSystemunderTest

– Organizedaccordingtoprogramdecisionstructure

public static int binsrch (int[] a, int key) {

int low = 0;int high = a.length - 1;

while (true) {

if ( low > high ) return -(low+1);

int mid = (low+high) / 2;

if ( a[mid] < key ) low = mid + 1;else if ( a[mid] > key ) high = mid - 1;else return mid;

}}

Whitebox testing

Could this array index be out of bounds?

Does this return statement ever get reached?

Will this statement get executed in a test?

Does it return the correct result?

Page 42: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4215-214

Codecoveragemetrics

• Methodcoverage– coarse• Branchcoverage– fine• Pathcoverage– toofine

– Costishigh,valueislow– (Relatedtocyclomatic complexity)

Page 43: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4315-214

MethodCoverage

• Tryingtoexecuteeachmethodaspartofatleastonetest

• Doesthisguaranteecorrectness?

Page 44: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4415-214

StatementCoverage• Tryingtotestallpartsoftheimplementation• Executeeverystatementinatleastonetest

• Doesthisguaranteecorrectness?

Page 45: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4515-214

StructureofCodeFragmenttoTest

Flow chart diagram forjunit.samples.money.Money.equals

Page 46: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4615-214

StatementCoverage• Statementcoverage

– Whatportionofprogramstatements(nodes)aretouchedbytestcases

• Advantages– Testsuitesizelinearinsizeofcode– Coverageeasilyassessed

• Issues– Deadcodeisnotreached– Mayrequiresomesophisticationto

selectinputsets– Fault-toleranterror-handlingcode

maybedifficultto“touch”– Metric:Couldcreateincentiveto

removeerrorhandlers!

Page 47: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4715-214

BranchCoverage• Branchcoverage

– Whatportionofconditionbranchesarecoveredbytestcases?

– Or:Whatportionofrelationalexpressionsandvaluesarecoveredbytestcases?

• Conditiontesting(Tai)

– Multicondition coverage– allbooleancombinationsoftestsarecovered

• Advantages– Testsuitesizeandcontentderived

fromstructureofbooleanexpressions– Coverageeasilyassessed

• Issues– Deadcodeisnotreached– Fault-toleranterror-handlingcode

maybedifficultto“touch”

Page 48: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4815-214

PathCoverage• Pathcoverage

– Whatportionofallpossiblepathsthroughtheprogramarecoveredbytests?

– Looptesting:Considerrepresentativeandedgecases:

• Zero,one,twoiterations• Ifthereisaboundn:n-1,n,n+1iterations• Nestedloops/conditionalsfrominsideout

• Advantages– Bettercoverageoflogicalflows

• Disadvantages– Infinitenumberofpaths– Notallpathsarepossible,ornecessary

• Whatarethesignificantpaths?– Combinatorialexplosionincasesunless

carefulchoicesaremade• E.g.,sequenceofniftestscanyield

upto2^npossiblepaths– Assumptionthatprogramstructureisbasically

sound

Page 49: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

4915-214

TestCoverageTooling

• Coverageassessmenttools– Trackexecutionofcodebytestcases

• Countvisitstostatements– Developreportswithrespecttospecificcoveragecriteria

– Instructioncoverage,linecoverage,branchcoverage

• Example:Cobertura andEclEmma forJUnit tests

Page 50: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5015-214

Page 51: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5115-214

Checkyourunderstanding

• Writetestcasestoachieve100%linecoveragebutnot100%branchcoverage

void foo(int a, int b) {if (a == b)

a = a * 2;if (a + b > 10)

return a - b;return a + b;

}

Page 52: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5215-214

Checkyourunderstanding

• Writetestcasestoachieve100%linecoverageandalso 100%branchcoverage

void foo(int a, int b) {if (a == b)

a = a * 2;if (a + b > 10)

return a - b;return a + b;

}

Page 53: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5315-214

Checkyourunderstanding

• Writetestcasestoachieve100%linecoverageand100%branchcoverageand 100%pathcoverage

void foo(int a, int b) {if (a == b)

a = a * 2;if (a + b > 10)

return a - b;return a + b;

}

Page 54: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5415-214

Coveragemetrics:usefulbutdangerous

• Cangivefalsesenseofsecurity• Examplesofwhatcoverageanalysiscouldmiss

– Datavalues– Concurrencyissues– raceconditionsetc.– Usabilityproblems– Customerrequirementsissues

• Highbranchcoverageisnot sufficient

Page 55: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5515-214

Testsuites– idealvs.real

• Idealtestsuites– Uncoverallerrorsincode– Test“non-functional”attributessuchasperformanceandsecurity

– Minimumsizeandcomplexity• RealtestSuites

– Uncoversomeportionoferrorsincode– Haveerrorsoftheirown– Arenonethelesspriceless

Page 56: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5615-214

STATICANALYSIS

Page 57: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5715-214

StupidBugs

public class CartesianPoint {private int x, y;int getX() { return this.x; }int getY() { return this.y; }public boolean equals(CartesianPoint that) {

return (this.getX()==that.getX()) && (this.getY() == that.getY());

}}

Page 58: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5815-214

Fin

dB

ug

s

Page 59: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

5915-214

Stupid Subtle Bugspublic class Object {

public boolean equals(Object other) { … }

// other methods…}

public class CartesianPoint extends Object {private int x, y;int getX() { return this.x; }int getY() { return this.y; }public boolean equals(CartesianPoint that) {

return (this.getX()==that.getX()) && (this.getY() == that.getY());

}}

classes with no explicit superclass implicitly extendObject

can’t change argument type when overriding

This defines a different equalsmethod, rather than overriding Object.equals()

Page 60: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6015-214

Fixing the Bug

public class CartesianPoint {private int x, y;int getX() { return this.x; }int getY() { return this.y; }

@Overridepublic boolean equals(Object o) {

if (!(o instanceof CartesianPoint)return false;

CartesianPoint that = (CartesianPoint) o;

return (this.getX()==that.getX()) && (this.getY() == that.getY());

}}

Declare our intent to override;Compiler checks that we did it

Use the same argument type as the method we are overriding

Check if the argument is a CartesianPoint.Correctly returns false if o is null

Create a variable of the right type, initializing it with a cast

Page 61: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6115-214

Fin

dB

ug

s

Page 62: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6215-214

Ch

eckS

tyle

Page 63: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6315-214

StaticAnalysis• Analyzingcodewithoutexecutingit(automatedinspection)• Looksforbugpatterns• Attemptstoformallyverifyspecificaspects• Pointouttypicalbugsorstyleviolations

– NullPointerExceptions– IncorrectAPIuse– Forgettingtocloseafile/connection– Concurrencyissues– Andmany,manymore(over250inFindBugs)

• IntegratedintoIDEorbuildprocess• FindBugsandCheckStyleopensource,manycommercial

productsexist

Page 64: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6415-214

ExampleFindBugsBugPatterns• Correctequals()• Useof==• Closingstreams• Illegalcasts• Nullpointerdereference• Infiniteloops• Encapsulationproblems• Inconsistentsynchronization• InefficientStringuse• Deadstoretovariable

Page 65: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6515-214

Bugfinding

Page 66: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6615-214

Canyoufindthebug?

if (listeners == null)

listeners.remove(listener);

JDK1.6.0, b105, sun.awt.x11.XMSelection

Page 67: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6715-214

Wrongbooleanoperator

if (listeners != null)

listeners.remove(listener);

JDK1.6.0, b105, sun.awt.x11.XMSelection

Page 68: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6815-214

Canyoufindthebug?

public String sendMessage (User user, String body, Date time) {

return sendMessage(user, body, null);

}

public String sendMessage (User user, String body, Date time, List attachments) {

String xml = buildXML (body, attachments);

String response = sendMessage(user, xml);

return response;

}

Page 69: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

6915-214

Infiniterecursiveloop

public String sendMessage (User user, String body, Date time) {

return sendMessage(user, body, null);

}

public String sendMessage (User user, String body, Date time, List attachments) {

String xml = buildXML (body, attachments);

String response = sendMessage(user, xml);

return response;

}

Page 70: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7015-214

Canyoufindthebug?

String aString = "bob";

b.replace('b', 'p');

if(b.equals("pop")){…}

Page 71: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7115-214

Methodignoresreturnvalue

String aString = "bob";

b = b.replace('b', 'p');

if(b.equals("pop")){…}

Page 72: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7215-214

Whatdoesthisprint?

Integer one = 1;Long addressTypeCode = 1L;

if (addressTypeCode.equals(one)) {System.out.println("equals");

} else {System.out.println("not equals");

}

Page 73: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7315-214

Whatdoesthisprint?

Integer one = 1;Long addressTypeCode = 1L;

if (addressTypeCode.equals(one)) {System.out.println("equals");

} else {System.out.println("not equals");

}

Page 74: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7415-214

ASIDE:FINDBUGS NULLPOINTERANALYSIS

Detector foo = null;foo.execute();

Page 75: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7515-214

FindBugs• Workson“.class”filescontainingbytecode

– Recall:Javasourcecodecompiledtobytecode;JVMexecutesbytecode

• Processingusingdifferentdetectors:– Independentofeachother– Maysharesomeresources(e.g.,controlflowgraph,dataflowanalysis)

– GOAL:Lowfalsepositives– Eachdetectorisdrivenbyasetofheuristics

• Output:bugpatterncode,sourcelinenumber,descriptivemessage(severity)

HIGHSEVERE RISK OF

PROGRAM FAILURE

MEDIUMELEVATED RISK OF PROGRAM FAILURE

LOWLOW RISK OF

PROGRAM FAILURE

Page 76: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7615-214

Nullpointerdereferencing• Findingsomenullpointerdereferencesrequiresophisticated

analysis:– Analyzingacrossmethodcalls,modelingcontentsofheapobjects

• Inpracticemanyexamplesofobvious nullpointerdereferences:– Valueswhicharealwaysnull– Valueswhicharenullonsomecontrolpath

• Howtodesignananalysistofindobviousnullpointerdereferences?– Idea:Lookforplaceswherevaluesareusedinasuspiciousway

From: https://www.cs.umd.edu/class/spring2005/cmsc433/lectures/findbugs.pdf

Page 77: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7715-214

SimpleAnalysis

Detector foo = null;foo.execute();

Dereferencing Null

Detector foo = new Detector(…);foo.execute();

Dereferencing NonNull

HIGHSEVERE RISK OF

PROGRAM FAILURE

J

Page 78: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7815-214

Ifonlyitwerethatsimple…

• Infeasiblepaths(falsepositives)

• Isamethod’sparameternull?

boolean b;if (p != null)

b = true;else

b = false;if (b)

p.f();

void foo(Object obj) {int x = obj.hashcode();…

}

Page 79: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

7915-214

Dataflowanalysis

• Ateachpointinamethod,keeptrackofdataflowfacts– E.g.,whichlocalvariablesandstacklocationsmightcontainnull

• Symbolicallyexecutethemethod:– Modelinstructions– Modelcontrolflow– Untilafixedpointsolutionisreached

Page 80: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8015-214

Dataflowvalues

• Modelvaluesoflocalvariablesandstackoperandsusinglatticeofsymbolicvalues

• Whentwocontrolpathsmerge,usemeet operatortocombinevalues:

Page 81: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8115-214

Dataflowvalues

• Modelvaluesoflocalvariablesandstackoperandsusinglatticeofsymbolicvalues

• Whentwocontrolpathsmerge,usemeet operatortocombinevalues:

Null⬦Null=Null

Page 82: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8215-214

Dataflowvalues

• Modelvaluesoflocalvariablesandstackoperandsusinglatticeofsymbolicvalues

• Whentwocontrolpathsmerge,usemeet operatortocombinevalues:

Null⬦ NotNull=MaybeNull

Page 83: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8315-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

Page 84: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8415-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

Page 85: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8515-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

x = nully = not nullz = not null

Page 86: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8615-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

x = nully = not nullz = not null

Page 87: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8715-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

x = nully = not nullz = not null

x = nully = nullz = null

Page 88: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8815-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

x = nully = maybez = maybe

Page 89: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

8915-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

x = null

Page 90: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9015-214

Null-pointerdataflowexamplex=y=z=null

y=new…z=new...

y.f()

x.f() z.f()

x = y = z = null;if (cond) {

y = new …;z = new …;

}y.f();if (cond2)

x.f();else

z.f();

z = uncertain

Page 91: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9115-214

Abstract Interpretation• Staticprogramanalysisisthesystematicexamination ofanabstractionofaprogram’sstatespace

• Abstraction– Don’ttrackeverything!(that’snormalinterpretation)– Trackanimportantabstraction

• Systematic– Ensureeverythingischeckedinthesameway

Details on how this works in 15-313

Page 92: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9215-214

COMPARINGQUALITYASSURANCESTRATEGIES

Page 93: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9315-214

Errorexists No errorexists

ErrorReported Truepositive(correctanalysisresult)

Falsepositive(annoying noise)

NoErrorReported Falsenegative(falseconfidence)

True negative(correctanalysisresult)

Sound Analysis: reports all defectsà no false negativestypically overapproximated

Complete Analysis:every reported defect is an actual defect à no false positivestypically underapproximated

Page 94: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9415-214

Checkyourunderstanding

• Whatisatrivialwaytoimplement:– asoundanalysis?– acompleteanalysis?

Page 95: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9515-214

DefectsreportedbySoundAnalysis

AllDefects

DefectsreportedbyCompleteAnalysis

UnsoundandIncompleteAnalysis

Page 96: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9615-214

Errorexists No errorexists

ErrorReported Truepositive(correctanalysisresult)

Falsepositive(annoying noise)

NoErrorReported Falsenegative(falseconfidence)

True negative(correctanalysisresult)

How does testing relate? And formal verification?

Sound Analysis: reports all defectsà no false negativestypically overapproximated

Complete Analysis:every reported defect is an actual defect à no false positivestypically underapproximated

Page 97: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9715-214

The Bad News: Rice's Theorem

• Everystaticanalysisisnecessarilyincompleteorunsoundorundecidable(ormultipleofthese)

• Eachapproachhasdifferenttradeoffs

"Any nontrivial property about the language recognized by a Turing machine is undecidable.“

Henry Gordon Rice, 1953

Page 98: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9815-214

Soundness/Completeness/PerformanceTradeoffs• Typecheckingdoescatchaspecificclassofproblems

(sound),butdoesnotfindallproblems• Compileroptimizationsmusterronthesafeside(only

performoptimizationswhensureit'scorrect;->complete)• Manypracticalbug-findingtoolsanalysesareunsoundand

incomplete– Catchtypicalproblems– Mayreportwarningsevenforcorrectcode– Maynotdetectallproblems

• Overwhelmingamountsoffalsenegativesmakeanalysisuseless

• Notall"bugs"needtobefixed

Page 99: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

9915-214

Testing, Static Analysis, and Proofs• Testing

– Observableproperties– Verifyprogramforoneexecution– Manualdevelopmentwith

automatedregression– Mostpracticalapproachnow– Doesnotfindallproblems

(unsound)

• StaticAnalysis– Analysisofallpossibleexecutions– Specificissuesonlywith

conservativeapprox.andbugpatterns

– Toolsavailable,usefulforbugfinding

– Automated,butunsoundand/orincomplete

• Proofs(FormalVerification)– Anyprogramproperty– Verifyprogramforallexecutions– Manualdevelopmentwith

automatedproofcheckers– Practicalforsmallprograms,may

scaleupinthefuture– Soundandcomplete,butnot

automaticallydecidable

What strategy touse in your project?

Page 100: Principles of Software Construction: Objects, Design, and …ckaestne/15214/s2017/slides/20170221-a… · 21/02/2017  · Bad Smells -> Design Defects • Bad Smells indicate that

10015-214

Take-HomeMessages

• Therearemanyformsofqualityassurance• Testingshouldbeintegratedintodevelopment

– possiblyeventestfirst• Variouscoveragemetricscanmoreorlessapproximatetestsuitequality

• Staticanalysistoolscandetectcertainpatternsofproblems

• Soundnessandcompletenesstocharacterizeanalyses