3. Program testing can be used
to show the presence of
bugs, but never to show
their absence!
(Dijkstra, 1970)
Edsger W. Dijkstra (1930 - 2002)
Notes on Structured Programming, Technological
University Eindhoven
6. Beck, Kent. 2 Hat Of Developer
Refactoring
When you're wearing the refactoring
hat, every change you make
preservers observable behavior,
keeps the tests green, and allows you
to make many small changes without
going near a debugger.
Adding function.
When you add function, however,
things are more open ended as you
will add tests and break existing
tests. The adding function hat is
more stressful and riskier, so it's
nice to wear the refactoring hat as
much as possible.
8. Key of Agile Development
The heart of Scrum is a Sprint, a time-box of one month or less during
which a "Done", useable, and potentially releasable product
Increment is created.
(Shuterland and Schwaber)
11. Level of Testing
Does the whole system work?
Does our code work against
code we can’t change?
Do our objects do the right
thing, are they convenient to
work with?
16. Dependecy Injection
Setup of dependency, is responsibility of the caller. Not The Dependent.
OrderService
DriverOjek
+ saveTarif()
<<use>>
DB
OrderService DriverOjek
21. FIRST Principle
● [F]ast ‒ imagine, every you stroke ctrl+s
● [I]solated ‒ avoid dependency to other unit test
● [R]epeatable ‒ it’s not truth, if not constant
● [S]elf-Validating ‒ avoid manual thing: setup, verification
● [T]imely ‒ later means never
24. Right Are the results right
B Are all the boundary conditions correct
I Can you check inverse relationship
C Can you cross-check result using others means
?
E Can you force error conditions to happen ?
P Are performance characteristics within bounds
?
Right-BICEP
25. 3 Laws of TDD*
1. You are not allowed to write any
production code unless it is to make a
failing unit test pass.
2. You are not allowed to write any more
of a unit test than is sufficient to fail;
and compilation failures are failures.
3. You are not allowed to write any more
production code than is sufficient to
pass the one failing unit test.
*iya, emang susah.
26. Further Reading
● Clean Code by Robert C Martin
● Pragmatic Unit Testing in Java 8 with JUnit by Jeff
Langr
● Google Clean Code Talks,
https://www.youtube.com/watch?v=wEhu57pih5w
● Three Laws of TDD,
https://www.youtube.com/watch?v=qkblc5WRn-U
● Uncle Bob Test Workshop,
https://www.youtube.com/watch?v=K7yR--yL0bc
Untuk mencapai poin [F]ast ‒ imagine, every you stroke ctrl+s
[I]solated ‒ avoid dependency to other unit test
[R]epeatable ‒ it’s not truth, if not constant,Dibutuhkan other skills of mocking : mimic bheavior
Untuk melakukan mimic beheavior, mockito menyediakan static function when().thenreturn().
So, out test will be like :
boundary conditions : error jsoninverse relationship : For mathematic computations, this is often the case: you can verify division with multiplication, addition with subtraction, and so on.
cross-check result using others means : pembukuan di akunting, atau order di amount oracle sama postgre
force error conditions : throw expection using mock
performance characteristics : profiling test