Unit Tests and Object References Implementing Classes in Java, using Documented Stubs, Test-First Programming
Check out UnitTesting and WordGames from SVN
Documented Stubs, Test-First Programming Check out UnitTesting and - - PowerPoint PPT Presentation
Unit Tests and Object References Implementing Classes in Java, using Documented Stubs, Test-First Programming Check out UnitTesting and WordGames from SVN Dont try to memorize the Java libraries Nearly 9000 classes and packages!
Check out UnitTesting and WordGames from SVN
Don’t try to memorize the Java libraries
Get in the habit of writing the javadocs bef
development skill
umented d stubs bs
Q1
Test-driven Development, unit testing and JUnit
Using code that you write to test other code
isolation
Individual methods Individual classes
Why would software engineers do unit testing?
Q2
JUnit is a unit testing framework
in another program.
JUnit was written by
Open-source software Now used by millions of Java developers Q3
MoveTester in Big Java shows how to write
Look at JUnitMoveTester in today’s repository
Test ―boundary conditions‖
Test known values: 100℃ == 212℉
Tests things that might go wrong
Vary things that are ―important‖ to the code
Important Slide: Use this as a reference!
Unit test shout, whisper, and holleWerld using ―interesting‖ test cases
Differences between primitive types and object types in Java
Variables of number type store values Variables of class type store references
Java keeps us from screwing up No & and * to worry about (and the people say, ―Amen‖)
Consider:
10
x
20
y
5 10 20 5
box
Q4
Actual value for number types Re
ct is not copied ied
erence nce va value ue (―the pointer‖) is copi pied
Consider:
10
x
10
y
8 5 6 7
box
box2
Q5 – Q6
Separating implementation details from how an object is used
Encapsulation—separating implementation
Functi tions
Objects ts Black box expose ses Function signature Constructor and method signatures Encapsul sulated ated inside e the e box Operation implementation Data storage ge and
erat ation
implementa ementatio tion
Q7 – Q8
But surely I owe you an accurate answer!
1. 1.
Create ate the (initially empty) class ss
2.
Write docu cumented ented stubs bs for the public interface of the class
3. 3.
Implem lemen ent the class ss:
additional instance fields as needed
4. 4.
Test t the e clas ass
implementing the constructor/method
WordGames Shouter
Censor
nsor: given a string inputString putString, produces a new string by replacing each occurrence of charTo arToCensor Censor with a ―*‖ (an asterisk).
How do you deal with char
arToCen ToCensor sor ?
No, that violates the StringTransformable interface
No, it needs to live for the entire lifetime of the Censor.
Answer: It is a field ! (What is a sensible name for the field?)
How do you initialize the field for char
harToCens ToCensor
WordGames Censor
Continue with homework if time permits
Q9 – Q10