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

57
1 17-214 Principles of Software Construction: Objects, Design, and Concurrency Invariants, immutability, and testing Josh Bloch Charlie Garrod Darya Melicher

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

Page 1: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

117-214

PrinciplesofSoftwareConstruction:Objects,Design,andConcurrency

Invariants,immutability,andtesting

JoshBloch CharlieGarrodDaryaMelicher

Page 2: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

217-214

Administrivia

• Homework4adueThursdayat11:59p.m.– Mandatorydesignreviewmeetingbeforethehomeworkdeadline

• PAvoterregistrationdeadline:Tuesday,October9th– https://www.pavoterservices.pa.gov/pages/VoterRegistrationApplication.aspx

Page 3: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

317-214

Unfinishedbusiness

Page 4: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

417-214

AsimplesolutiontoHW2– Mainclass

Page 5: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

517-214

HowdoweturnHW2intoHW3?

Page 6: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

617-214

Lessons(practical)

• Chooselowlevelabstractionsthatmakehigherleveltaskseasy• Whenyouwanttorepresentafixedsetofvaluesknownat

compiletime,considerenums• Ifusersneedtoextendthesetconsideremulatedextensibleenum• Bittwiddlingshouldbepartofeveryprogrammerstoolkit

– Don’toveruseit…– Butdoconsiderit,especiallywhenyouneedhighperformance

Page 7: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

717-214

Lessons(philosophical)

• Goodhabitsmatter– “Thewaytowriteaperfectprogramistomakeyourselfaperfect

programmerandthenjustprogramnaturally.”– WattsS.Humphrey,1994

• Don’tjusthackitupandsayyou’llfixitlater– Youprobablywon’t– butyouwillgetintothehabitofjusthackingitup– Alsoit’swaymore fun toworkonnice,well-structuredcode

• Evensmalldesigndecisionsmatter– Ifyourcodeisgettingugly,gobacktothedrawingboard– “Aweekofcodingcanoftensaveawholehourofthought.”

• Striveforclarity– It’snotenoughtobemerelycorrect;aimforclearlycorrect

Page 8: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

817-214

Outline

• Classinvariantsanddefensivecopying• Immutability• Testingandcoverage• Testingforcomplexenvironments

Page 9: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

917-214

Classinvariants

• Criticalpropertiesofthefieldsofanobject• Establishedbytheconstructor• Maintainedbypublicmethodinvocations

– Maybeinvalidatedtemporarilyduringmethodexecution

Page 10: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1017-214

Safelanguagesandrobustprograms

• UnlikeC/C++,Javalanguagesafe– Immunetobufferoverruns,wildpointers,etc.

• Makesitpossibletowriterobust classes– Correctnessdoesn’tdependonothermodules– Eveninsafelanguage,requiresprogrammereffort

Page 11: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1117-214

Defensiveprogramming

• Assumeclientswilltrytodestroyinvariants– Mayactuallybetrue(malicioushackers)– Morelikely:honestmistakes

• Ensureclassinvariantssurviveanyinputs– Defensivecopying– Minimizingmutability

Page 12: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1217-214

Thisclassisnotrobust

public final class Period {private final Date start, end; // Invariant: start <= end

/*** @throws IllegalArgumentException if start > end* @throws NullPointerException if start or end is null*/public Period(Date start, Date end) {

if (start.after(end))throw new IllegalArgumentException(start + " > " + end);

this.start = start;this.end = end;

}

public Date start() { return start; }public Date end() { return end; }... // Remainder omitted

}

Page 13: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1317-214

Theproblem:DateismutableObsoleteasofJava8;sadlynotdeprecatedeveninJava11

// Attack the internals of a Period instanceDate start = new Date(); // (The current time)Date end = new Date(); // " " "Period p = new Period(start, end);end.setYear(78); // Modifies internals of p!

Page 14: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1417-214

Thesolution:defensivecopying

// Repaired constructor - defensively copies parameterspublic Period(Date start, Date end) {

this.start = new Date(start.getTime());this.end = new Date(end.getTime());if (this.start.after(this.end))

throw new IllegalArgumentException(start + " > "+ end);}

Page 15: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1517-214

Afewimportantdetails

• Copiesmadebeforecheckingparameters• Validitycheckperformedoncopies• Eliminateswindowofvulnerabilitybetweenvaliditycheck&copy• ThwartsmultithreadedTOCTOUattack

– Time-Of-Check-To-Time-Of-U

// BROKEN - Permits multithreaded attack!public Period(Date start, Date end) {

if (start.after(end))throw new IllegalArgumentException(start + " > " + end);

// Window of vulnerabilitythis.start = new Date(start.getTime());this.end = new Date(end.getTime());

}

Page 16: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1617-214

Anotherimportantdetail

• Usedconstructor,notclone,tomakecopies– NecessarybecauseDateclassisnonfinal– Attackercouldimplementmalicioussubclass

• Recordsreferencetoeachextantinstance• Providesattackerwithaccesstoinstancelist

• Butwhousesclone,anyway?[EJItem11]

Page 17: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1717-214

Unfortunately,constructorsareonlyhalfthebattle

// Accessor attack on internals of PeriodPeriod p = new Period(new Date(), new Date());Date d = p.end();p.end.setYear(78); // Modifies internals of p!

Page 18: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1817-214

Thesolution:moredefensivecopying

// Repaired accessors - defensively copy fieldspublic Date start() {

return new Date(start.getTime());}public Date end() {

return new Date(end.getTime());}

NowPeriodclassisrobust!

Page 19: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

1917-214

Summary

• Don’tincorporatemutableparametersintoobject;makedefensivecopies

• Returndefensivecopiesofmutablefields…• Orreturnunmodifiable viewofmutablefields• Reallesson– useimmutable components

– Eliminatestheneedfordefensivecopying

Page 20: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2017-214

Outline

• Classinvariantsanddefensivecopying• Immutability• Testingandcoverage• Testingforcomplexenvironments

Page 21: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2117-214

Immutableclasses

• Classwhoseinstancescannotbemodified• Examples:String,Integer,BigInteger,Instant• How,why,andwhentousethem

Page 22: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2217-214

Howtowriteanimmutableclass

• Don’tprovideanymutators• Ensurethatnomethodsmaybeoverridden• Makeallfieldsfinal• Makeallfieldsprivate• Ensuresecurityofanymutablecomponents

Page 23: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2317-214

public final class Complex {private final double re, im;

public Complex(double re, double im) {this.re = re;this.im = im;

}

// Getters without corresponding setterspublic double realPart() { return re; }public double imaginaryPart() { return im; }

// minus, times, dividedBy similar to addpublic Complex plus(Complex c) {

return new Complex(re + c.re, im + c.im);}

Immutableclassexample

Page 24: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2417-214

@Override public boolean equals(Object o) {if (!(o instanceof Complex)) return false;Complex c = (Complex) o;return Double.compare(re, c.re) == 0 &&

Double.compare(im, c.im) == 0;}

@Override public int hashCode() {return 31 * Double.hashCode(re) + Double.hashCode(im);

}

@Override public String toString() {return String.format("%d + %di", re, im)";

}}

Immutableclassexample(cont.)Nothinginterestinghere

Page 25: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2517-214

Distinguishingcharacteristic

• Returnnewinstanceinsteadofmodifying• Functionalprogramming• Mayseemunnaturalatfirst• Manyadvantages

Page 26: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2617-214

Advantages

• Simplicity• InherentlyThread-Safe• Canbesharedfreely• Noneedfordefensivecopies• Excellentbuildingblocks

Page 27: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2717-214

Majordisadvantage

• Separateinstanceforeachdistinctvalue• Creatingtheseinstancescanbecostly

BigInteger moby = ...; // A million bits longmoby = moby.flipBit(0); // Ouch!

• Problemmagnifiedformultistepoperations– Well-designedimmutableclassesprovidecommonmultistepoperations

• e.g.,myBigInteger.modPow(exponent, modulus)– Alternative:mutablecompanionclass

• e.g.,StringBuilder forString

Page 28: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2817-214

Whentomakeclassesimmutable

• Always,unlessthere'sagoodreasonnotto• Alwaysmakesmall“valueclasses”immutable!

– Examples:Color,PhoneNumber,Unit– Date andPoint weremistakes!– Expertsoftenuselong insteadofDate

Page 29: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

2917-214

Whentomakeclassesmutable

• Classrepresentsentitywhosestatechanges– Real-world- BankAccount,TrafficLight– Abstract- Iterator, Matcher, Collection– Processclasses- Thread,Timer

• Ifclassmustbemutable,minimizemutability– Constructorsshouldfullyinitializeinstance– Avoidreinitializemethods

Page 30: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3017-214

Outline

• ClassInvariants• Immutability• Testingandcoverage• Testingforcomplexenvironments

Page 31: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3117-214

Whydowetest?

Page 32: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3217-214

Testingdecisions

• Whotests?– Developerswhowrotethecode– QualityAssuranceTeamandTechnicalWriters– Customers

• Whentotest?– Beforeandduringdevelopment– Aftermilestones– Beforeshipping– Aftershipping

Page 33: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3317-214

Testdrivendevelopment

• Writetestsbeforecode• Neverwritecodewithoutafailingtest• Codeuntilthefailingtestpasses

Page 34: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3417-214

Whyusetestdrivendevelopment?

• Forcesyoutothinkaboutinterfacesearly• Higherproductquality

– Bettercodewithfewerdefects

• Highertestsuitequality• Higherproductivity• It’sfuntowatchtestspass

Page 35: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3517-214

TDDinpractice

• EmpiricalstudiesonTDDshow:– Mayrequiremoreeffort– Mayimprovequalityandsavetime

• SelectiveuseofTDDisbest• AlwaysuseTDDforbugreports

– Regressiontests

Page 36: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3617-214

Howmuchtesting?

• Yougenerallycannottestallinputs– Toomany– usuallyinfinite

• Butwhenitworks,exhaustivetestingisbest!

Page 37: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3717-214

Whatmakesagoodtestsuite?

• Provideshighconfidencethatcodeiscorrect• Short,clear,andnon-repetitious

– Moredifficultfortestsuitesthanregularcode– Realistically,testsuiteswilllookworse

• Canbefuntowriteifapproachedinthisspirit

Page 38: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3817-214

Nextbestthingtoexhaustivetesting:randominputs

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

– Chooseinputstotickleinterestingcases– Knowledgeofimplementationhelpshere

• Seedrandomnumbergeneratorsotestsrepeatable

Page 39: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

3917-214

Black-boxtesting

• Lookatspecifications,notcode• Testrepresentativecases• Testboundaryconditions• Testinvalid(exception)cases• Don’ttestunspecifiedcases

Page 40: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4017-214

White-boxtesting

• Lookatspecificationsand code• Writeteststo:

– Checkinterestingimplementationcases– Maximizebranchcoverage

Page 41: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4117-214

Codecoveragemetrics

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

– Costishigh,valueislow– (Relatedtocyclomatic complexity)

Page 42: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4217-214

Coveragemetrics:usefulbutdangerous

• Cangivefalsesenseofsecurity• Examplesofwhatcoverageanalysiscouldmiss

– Datavalues– Concurrencyissues– raceconditions,etc.– Usabilityproblems– Customerrequirementsissues

• Highbranchcoverageisnot sufficient

Page 43: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4317-214

Testsuites– idealandreal

• Idealtestsuiteswould– Uncoverallerrorsincode– Test“non-functional”attributessuchasperformanceandsecurity– Minimumsizeandcomplexity

• RealtestSuites– Uncoversomeportionoferrorsincode– Haveerrorsoftheirown– Arenonethelesspriceless

Page 44: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4417-214

Outline

• Classinvariants• Immutability• Testingandcoverage• Testingforcomplexenvironments

Page 45: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4517-214

Problemswhentestingsomeapps

• User-facingapplications– Usersclick,drag,etc.,andinterpretoutput– Timingissues

• Testingagainstbiginfrastructure– Databases,webservices,etc.

• Realworldeffects– Printing,mailingdocuments,etc.

• Collectivelycomprisethe testenvironment

Page 46: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4617-214

Example– Tiramisuapp

• Mobilerouteplanningapp• AndroidUI• BackenduseslivePATdata

Page 47: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4717-214

Anotherexample

• 3rdpartyFacebook apps• Androiduserinterface• BackendusesFacebook data

Page 48: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4817-214

Testinginrealenvironments

Code FacebookAndroidclient

void buttonClicked() {render(getFriends());

}

List<Friend> getFriends() {Connection c = http.getConnection();FacebookApi api = new FacebookApi(c);List<Node> persons = api.getFriends("john");for (Node person1 : persons) {

for (Node person2 : persons) {…}

}return result;

}

Page 49: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

4917-214

EliminatingAndroiddependency

Code FacebookTestdriver

@Test void testGetFriends() {... // A Junit test

}

List<Friend> getFriends() {Connection c = http.getConnection();FacebookApi api = new FacebookApi(c);List<Node> persons = api.getFriends("john");for (Node person1 : persons) {

for (Node person2 : persons) {…}

}return result;

}

Page 50: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5017-214

Thatwon’tquitework

• GUIapplicationsprocessmany thousands ofevents• Solution:automatedGUItestingframeworks

– AllowstreamsofGUIeventstobecaptured,replayed

• Thesetoolsaresometimescalledrobots

Page 51: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5117-214

EliminatingFacebook dependency

Code MockFacebook

@Test void testGetFriends() {... // A Junit test

}

List<Friend> getFriends() {FacebookApi api = new MockFacebook(c);List<Node> persons = api.getFriends("john");for (Node person1 : persons) {

for (Node person2 : persons) {…}

}return result;

}

Testdriver

Page 52: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5217-214

Thatwon’tquitework!

• Changingproductioncodefortestingunacceptable• Problemcausedbyconstructor incode• Insteadofconstructor,usespecialfactorythatallowsalternative

implementations• Usetoolstofacilitatethissortoftesting

– Dependencyinjectiontools,e.g.,Dagger,Guice,Spring– MockobjectframeworkssuchasMockito

Page 53: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5317-214

Faultinjection

• Mockscanemulatefailuressuchastimeouts• Allowsyoutoverifytherobustnessofsystemagainstfaultsthat

youcan’tgenerateatwill

Code MockFacebookTestdriver

Page 54: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5417-214

Advantagesofusingmocks

• Testcodelocallywithoutlargeenvironment• Enabledeterministictests(insomecases)• Enablefaultinjection• Canspeeduptestexecution

– e.g.,avoidslowdatabaseaccess

• Cansimulatefunctionalitynotyetimplemented• Enabletestautomation

Page 55: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5517-214

DesignImplications

• Thinkabouttestabilitywhenwritingcode• Whenamockmaybeappropriate,designforit• Hidesubsystemsbehindaninterfaces• Usefactories,notconstructorstoinstantiate• Useappropriatetools

– Dependencyinjectionormockingframeworks

Page 56: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5617-214

MoreTestingin15-313FoundationsofSoftwareEngineering

• Manualtesting• Securitytesting,penetrationtesting• Fuzztestingforreliability• Usabilitytesting• GUI/Webtesting• Regressiontesting• Differentialtesting• Stress/soaktesting

Page 57: Principles of Software Construction: Objects, Design, and ...charlie/courses/17-214/2018-fall/slides/... · 17-214 1 Principles of Software Construction: Objects, Design, and Concurrency

5717-214

Conclusion

• Tomaintainclassinvariants– Minimizemutability– Makedefensivecopieswhererequired

• Interfacetestingiscritical– Designinterfacestofacilitatetesting– Writecreativetestsuitesthatmaximizepower-to-weightratio– Coveragetoolscanhelpgaugetestsuitequality

• Testingappswithcomplexenvironmentsrequiresaddedeffort