Towards a Taxonomy of Unit Tests
-
Upload
esug -
Category
Technology
-
view
225 -
download
0
description
Transcript of Towards a Taxonomy of Unit Tests
![Page 1: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/1.jpg)
Towards aTaxonomy of Unit Tests
Markus GälliOscar Nierstrasz
Software Composition GroupUniversity of Bern
Michele LanzaFaculty of InformaticsUniversity of Lugano
![Page 2: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/2.jpg)
Navigating & ComposingUnit Tests is difficult
Goal: Facilitate the- navigation between tests and methods- composition of complex test scenariosQuestions:- What are the relationships between
- tests and methods- tests and tests
One Metric:- What kind of unit tests with respect to theserelations occur how often? -> Taxonomy
![Page 3: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/3.jpg)
The root of our Taxonomy:Does a test focus on one method?
![Page 4: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/4.jpg)
One-Method Commands:One-Method Tests and Examples
![Page 5: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/5.jpg)
One-Method Test
• Definition“Tests the outcome of exactly one call of amethod under test.”
• ExampleYearMonthWeekTest>>testIndexOfDay
self assert:(Week indexOfDay:'Friday')=6.
• Occurrences53% of the Squeak Tests
![Page 6: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/6.jpg)
One-Method Test Suite
• DefinitionTests the outcome of the method under test in several situations:
• ExampleYearMonthWeekTest>>testDaysInMonthself assert:(Month daysInMonth:2 forYear: 2000)=29.self assert:(Month daysInMonth:2 forYear: 2001)=28.self assert:(Month daysInMonth:2 forYear: 2004)=29.self assert:(Month daysInMonth:2 forYear: 2100)=28.
• Occurrences15% of the Squeak Tests
![Page 7: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/7.jpg)
Pessimistic Method Example• Definition
checks that an exception is thrown if a method is called in a way whichviolates a precondition.
• ExampleDosFileDirectoryTests>>testFileDirectoryNonExistence"Hoping that you have 'C:' of course...”FileDirectory activeDirectoryClass ==DosFileDirectory
ifFalse:[^self].self should: [(FileDirectory basicNew fileOrDirectoryExists: 'C:')]
raise:InvalidDirectoryError.• Occurrences
2% of the Squeak Tests
![Page 8: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/8.jpg)
Optimistic Method Example• Definition
expects that no exception is thrown if the method under test is called withoutviolating some preconditions. .
• ExampleBitBLTClipBugs>>testDrawingWayOutside2|f1 bb f2 |f1 := Form extent: 100@100 depth: 1.f2 := Form extent: 100@100 depth: 1.bb := BitBlt toForm: f1.bb combinationRule: 3.bb sourceForm: f2.bb destOrigin: [email protected] width: SmallInteger maxVal squared; height: SmallInteger maxVal squared.self shouldnt:[bb copyBits] raise: Error.
• Occurrences2% of the Squeak Tests
![Page 9: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/9.jpg)
Multiple-Method Commandsare decomposable
![Page 10: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/10.jpg)
Multi-Facet Test Suite(decomposable into One-Method Tests)
• Definition reuses a scenario to test several candidate methods
• ExampleTimeTest>>testPrintingself
assert: time printString = '4:02:47 am';assert: time intervalString =
'4 hours 2 minutes 47 seconds';assert: time print24 = '04:02:47';assert: time printMinutes = '4:02 am';assert: time hhmm24 = '0402'.
• Occurrences2% of the Squeak Tests
![Page 11: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/11.jpg)
Cascaded Test Suite(decomposable into One-Method Tests)
• Definition
results of one test are used to perform the next test• Example
Base64MimeConverterTest>>testMimeEncodeDecode|encoded|encoded _ Base64MimeConverter mimeEncode: message.self should: [encoded contents = 'SGkgVGhlcmUh'].self should:[(Base64MimeConverter mimeDecodeToChars:encoded) contents = message contents].
• Occurrences4% of the Squeak Tests
![Page 12: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/12.jpg)
Constraint Test(decomposable into One-Method Commands)
• Definition
checks the interplay of several methods without focusing on one of them.• Example
PNGReadWriterTest>>test16Bitself encodeAndDecodeForm:(self drawStuffOn:
(Form extent: 33@33 depth: 16))• Occurrences
10% of the Squeak Tests
![Page 13: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/13.jpg)
A Five Pane Browser…
![Page 14: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/14.jpg)
Conclusion
• We built a terminology to denote existingunit tests with respect to composition
• Most unit tests of Squeak do focus on onemethod
• Tests are decomposable into one methodcommands
• One method commands can be linked andcomposed easily
![Page 15: Towards a Taxonomy of Unit Tests](https://reader033.fdocuments.in/reader033/viewer/2022052901/556bf517d8b42a65458b53bb/html5/thumbnails/15.jpg)
The Taxonomy