Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section...

11
Programming By Programming By Intention/ Intention/ Intro to JUnit Intro to JUnit

Transcript of Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section...

Page 1: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

Programming By Programming By Intention/Intention/

Intro to JUnitIntro to JUnit

Page 2: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

AdminAdmin

► Astels, p. 50 – “The test in the section titled Astels, p. 50 – “The test in the section titled Programming by IntentionProgramming by Intention…” should read “The …” should read “The test in the section titled test in the section titled Do the Simplest Do the Simplest Thing…Thing…””

►QuizzesQuizzes Read the questionRead the question Handling quiz opt-outsHandling quiz opt-outs Two items != one item worded two waysTwo items != one item worded two ways Refactoring key – Not changing functionalityRefactoring key – Not changing functionality Shotgun Surgery = having to make changes in Shotgun Surgery = having to make changes in

multiple places for one functional changemultiple places for one functional change

Page 3: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

Programming By Intention Programming By Intention

►Methods for keeping code as good as Methods for keeping code as good as possiblepossible

►Guidelines we’ll follow for code we Guidelines we’ll follow for code we write in this classwrite in this class

Page 4: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

NamingNaming

►Nouns for class names/variables Nouns for class names/variables (Person, Order, Item)(Person, Order, Item)

►Adjectives/generic nouns for interfaces Adjectives/generic nouns for interfaces (Testable, Database, Iterator)(Testable, Database, Iterator)

►Verbs for method names (Save, Verbs for method names (Save, calculateTotalInterest)calculateTotalInterest)

►getX(), setX(), isX(), hasX()getX(), setX(), isX(), hasX()►Leave out redundant infoLeave out redundant info

Page 5: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

SimplicitySimplicity

►Make code as simple as possible to do Make code as simple as possible to do what’s neededwhat’s needed

►Use refactorings to keep things simpleUse refactorings to keep things simple►Use test-first programmingUse test-first programming

Page 6: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

AssumptionsAssumptions

►Make assumptions while you write your Make assumptions while you write your testtest

►Makes you think about your code from Makes you think about your code from the standpoint of using the code, which the standpoint of using the code, which means your code plays better with means your code plays better with othersothers

►Don’t worry about tracking the Don’t worry about tracking the assumptions you make, let the compiler assumptions you make, let the compiler tell youtell you

Page 7: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

CommentsComments

►Not all comments are badNot all comments are bad► Examples of good commentsExamples of good comments

Todo items – incomplete codeTodo items – incomplete code Future refactorings (either by you or someone Future refactorings (either by you or someone

else)else) Use of uncommon acronymUse of uncommon acronym AttributionAttribution Changes made for specific reason (e.g., Changes made for specific reason (e.g.,

performance tuning)performance tuning) Brief class overviewBrief class overview

Page 8: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

JUnitJUnit

►Developed by Kent Beck and Erich Developed by Kent Beck and Erich GammaGamma

►Variant of sUnit (Smalltalk)Variant of sUnit (Smalltalk)►Current version = 3.8.1Current version = 3.8.1► Included in Eclipse and many other Included in Eclipse and many other

IDEsIDEs

Page 9: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

StructureStructure

►Test CasesTest Cases Extend JUnit TestCase classExtend JUnit TestCase class Contain methods which perform actual testsContain methods which perform actual tests Main piece for TDDMain piece for TDD

►Test SuitesTest Suites Contain Test Cases and/or other Test SuitesContain Test Cases and/or other Test Suites Default Test Suite contains all testsDefault Test Suite contains all tests Generally explicitly defined to allow running Generally explicitly defined to allow running

subsets of tests subsets of tests

Page 10: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

AssertsAsserts

►Actual checks performed by test Actual checks performed by test methodsmethods

►Two forms – use one with extra string Two forms – use one with extra string paramparam

►Fail()Fail()►assertTrue/assertFalseassertTrue/assertFalse►assertNull/assertNotNullassertNull/assertNotNull►assertSame/assertNotSameassertSame/assertNotSame►assertEqualsassertEquals

Page 11: Programming By Intention/ Intro to JUnit. Admin ► Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in.

Eclipse DemoEclipse Demo