10/25/2015
Watch the google talk "The clean code talks - unit testing", write down notes and then learn better for next time.
video link:
https://www.youtube.com/watch?v=wEhu57pih5w
Video time:
02:02 / 32:07
Hard to test code
Most People say:
Make things private
Using final keyword
Long methods
Real issues: (interview questions)
Mixing new with logic
Work in constructor
Global state
Singleton
Static Methods (procedure programming) (leaf method vs way-up method)
Deep inheritance (Divorce myself from inheritance at run time. )
Too many conditionals ()
Procedure code - Seam - Polymorphism - Julia's comment: look into it, read more about it. 10/25/2015
Video time:
14:35/32:07
Progression of Testing:
1. Scenario / Large Tests
Test whole applicatio by prentending to be a user
slow / Flaky / Mostly happy paths
2. Functional / Medium Tests
External dependencies simulated
Test class interaction
3. Unit / Small Tests
Focus on application logic
Very Fast / No I/O / No Need for a debugger
4. Think of it more as a continuum than discrete
5. All tests levels important
Not all levels have the same probability of a bug
Because smaller tests cover less need more of them
6. Testability more important as you get more focused
Video time:
17:05 /32:07
Different kinds of Tests
Execution time :
unit test -> Functional Tests -> Scenario
Test individual ->
Test collections of classes as subsytems ->
Test the whole system pretending to be a user
Video time:
27:06/32:07
How do you write hard to test code?
You mix object creation code with business logic
This will assure that a test case never can construct a graph of objects different from production. Hence nothing can be tested in isolation.
Unit test class -
Seam - friendly - try to understand the dependency injection
class depends on a lot of other classes, mocking, seam, learned through hacking,
class:
object graph
construction & lookup
business logic
27:36/32:07
Take Away
Unit tests are a preferred way of testing
Unit tests require seperation of instantiation of object graph from business logic under test
Questions:
1. Global variable - make test unpredictable, the order of test matters and so on and so forth.
Do not clean up after yourself, another test will fail;
Counter argument: framework than DI framework.
Monkey-patching - evil on the global state - dependency injection
C++ / Java / frameworks - dependency injection difference
And read the slideshow using the following link:
http://www.slideshare.net/avalanche123/clean-code-5609451
http://misko.hevery.com/code-reviewers-guide/
http://misko.hevery.com/presentations/
http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
No comments:
Post a Comment