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

§Refactoring key – Not changing functionality

§Shotgun Surgery = having to make changes in multiple places for one functional change

Programming By Intention

Methods for keeping code as good as possible

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

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

Simplicity

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

Use refactorings to keep things simple

Use test-first programming

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

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

JUnit

Developed by Kent Beck and Erich Gamma

Variant of sUnit (Smalltalk)

Current version = 3.8.1

Included in Eclipse and many other IDEs

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

Asserts

Actual checks performed by test methods

Two forms – use one with extra string param

Fail()

assertTrue/assertFalse

assertNull/assertNotNull

assertSame/assertNotSame

assertEquals

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值