1 / 11

Programming By Intention/ Intro to JUnit

Programming By Intention/ Intro to JUnit. Admin. Astels, p. 50 – “The test in the section titled Programming by Intention …” should read “The test in the section titled Do the Simplest Thing… ” Quizzes Read the question Handling quiz opt-outs Two items != one item worded two ways

Download Presentation

Programming By Intention/ Intro to JUnit

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming By Intention/Intro to JUnit

  2. Admin • Astels, p. 50 – “The test in the section titled Programming by Intention…” should read “The test in the section titled Do the Simplest Thing…” • Quizzes • Read the question • Handling quiz opt-outs • Two items != one item worded two ways • Refactoring key – Not changing functionality • Shotgun Surgery = having to make changes in multiple places for one functional change

  3. Programming By Intention • Methods for keeping code as good as possible • Guidelines we’ll follow for code we write in this class

  4. Naming • Nouns for class names/variables (Person, Order, Item) • Adjectives/generic nouns for interfaces (Testable, Database, Iterator) • Verbs for method names (Save, calculateTotalInterest) • getX(), setX(), isX(), hasX() • Leave out redundant info

  5. Simplicity • Make code as simple as possible to do what’s needed • Use refactorings to keep things simple • Use test-first programming

  6. Assumptions • Make assumptions while you write your test • Makes you think about your code from the standpoint of using the code, which means your code plays better with others • Don’t worry about tracking the assumptions you make, let the compiler tell you

  7. Comments • Not all comments are bad • Examples of good comments • Todo items – incomplete code • Future refactorings (either by you or someone else) • Use of uncommon acronym • Attribution • Changes made for specific reason (e.g., performance tuning) • Brief class overview

  8. JUnit • Developed by Kent Beck and Erich Gamma • Variant of sUnit (Smalltalk) • Current version = 3.8.1 • Included in Eclipse and many other IDEs

  9. Structure • Test Cases • Extend JUnit TestCase class • Contain methods which perform actual tests • Main piece for TDD • Test Suites • Contain Test Cases and/or other Test Suites • Default Test Suite contains all tests • Generally explicitly defined to allow running subsets of tests

  10. Asserts • Actual checks performed by test methods • Two forms – use one with extra string param • Fail() • assertTrue/assertFalse • assertNull/assertNotNull • assertSame/assertNotSame • assertEquals

  11. Eclipse Demo

More Related