DOC PREVIEW
Toronto CSC 302 - Lecture 19 - Automated Testing

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 1Lecture 19:Automated TestingStrategy for automated testsJUnit and familyTesting GUI-based softwareTest coverage for Object-Oriented SystemsUniversity of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 2Automated Testing StrategySetupExerciseVerifyTeardownSUT(SystemunderTest)DOC(depended-On Component)InitializeExercise (with return value)Get StateGet Something(with return value)Do something(no return value)Direct control pointsIndirect control pointDirect observation pointsIndirect observation pointsTestCaseFixtureTest DoubleSource: Adapted from Meszaros 2007, p662University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 3Test Order?InsideOutOutsideInSource: Adapted from Meszaros 2007, p35University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 4How JUnit worksSource: Adapted from Meszaros 2007, p773University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 5Principles of Automated TestingWrite the Test Cases FirstDesign for TestabilityUse the Front Door Firsttest via public interfaceavoid creating back door manipulationCommunicate IntentTests as Documentation!Make it clear what each test doesDon’t Modify the SUTavoid test doublesavoid test-specific subclasses(unless absolutely necessary)Keep tests IndependentUse fresh fixturesAvoid shared fixturesIsolate the SUTMinimize Test OverlapVerify One Condition Per TestTest Concerns SeparatelyMinimize Untestable codee.g. GUI componentse.g. multi-threaded codeetcKeep test logic out of productioncodeNo test hooks!Source: Adapted from Meszaros 2007, p39-48University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 6Testing interactive software1) Start UMLet2) Click on File -> Open3) select test2.uxf4) click Open4University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 7Automating the testingChallenges for automated testing:Synchronization - How do we know a window popped open that we can click in?Abstraction - How do we know it’s the right window?Portability - What happens on a display with different resolution / size, etcUnitsFunctionalityPresentationAutomatedtestsManualtestsSource: Adapted from Zeller 2006, p57University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 8Presentation LayerScript the mouse and keyboard eventsscript can be recorded (e.g. “send_xevents @400,100”)script is write-only and fragileScript at the application function levelE.g. Applescript: tell application ”UMLet" to activateRobust against size and position changesFragile against widget renamings, layout changes, etc.Write an API for your application…Source: Adapted from Zeller 2006, chapter 35University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 9Circular DependenciesCore+print_to_file()UserPresentation+confirm_loss()void print_to_file(string filename){ if (path_exists(filename)) { // FILENAME exists; ask user to confirm overwrite bool confirmed = confirm_loss(filename); if (!confirmed) return; } // Proceed printing to FILENAME...}Source: Adapted from Zeller 2006, chapter 3University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 10Revised DependencyCore+print_to_file()Presentation+confirm_loss()UserPresentation+confirm_loss()AutoPresentation+confirm_loss()ask user return true;Source: Adapted from Zeller 2006, chapter 36University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 11Testing Object Oriented CodeEncapsulationIf the object hides it’s internal state, how do we test it?E.g. add methods only to be used in testing, which expose internal stateBut: how do we know these extra methods are correct?InheritanceWhen a subclass extends a well-tested class, what extra testing is needed?e.g. Test just the overridden methods?But with dynamic binding, this is not sufficiente.g. other methods can change behaviour because they call over-ridden methodsPolymorphismWhen class A calls class B, it might actually be interacting with any of B’ssubclasses…University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 12Consider this program…Base+foo()+bar()-helper()Derived-helper()class Base { public void foo() { … helper(); … } public void bar() { … helper(); … } private helper() {…}}class Derived extends Base { private helper() {…}}Source: Adapted from IPL 19997University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available free for non-commercial use with attribution under a creative commons license. 13Test Casespublic void testFoo() { Base b = new Base(); b.foo();}public void testBar() { Derived d = new Derived(); d.bar();}Base+foo() -- Exercised in testFoo+bar() -- Untested!-helper() -- Exercised in testFooDerived{+foo()} -- Untested!{+bar()} -- Exercised in testBar-helper() -- Exercised in testBarinherited methodsSource: Adapted from IPL 1999University of TorontoDepartment of Computer Science© 2008 Steve Easterbrook. This presentation is available


View Full Document

Toronto CSC 302 - Lecture 19 - Automated Testing

Documents in this Course
Load more
Download Lecture 19 - Automated Testing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 19 - Automated Testing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 19 - Automated Testing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?