SlideShare una empresa de Scribd logo
1 de 20
I Hate Unit Test!!!
                Daniel Teng, Certified Scrum Coach




                     www.danielteng.com
12年2月25日星期六
A Brand-new Legacy Project
                    www.danielteng.com
12年2月25日星期六
The Pain Point
               www.danielteng.com
12年2月25日星期六
AccountService.LogOn(LogOnModel model)




                 www.danielteng.com
12年2月25日星期六
The Logic Flow
               www.danielteng.com
12年2月25日星期六
Broken Window
                www.danielteng.com
12年2月25日星期六
Misko Hevery




              Test Iceberg
              www.danielteng.com
12年2月25日星期六
But, What is Unit Test
                    Anyway?


                   www.danielteng.com
12年2月25日星期六
A Test is NOT a Unit
                      Test If:

       • It talks to the database
       • It communicates across the network
       • It touches the file system
       • It can't run at the same time as any of your other
         unit tests
       • You have to do special things to your
         environment (such as editing config files) to run it.

                        www.danielteng.com
12年2月25日星期六
I will do UT when I start
            a green field project
          •    Legacy codebase

          •    UI is not testable

          •    It is QA’s job

          •    It doesn’t catch bug

          •    Too many dependencies
                           Real Reason change, I will have
          •    It double effort because when code
               to change tests too.
              I don’t know how to write!!!
                            www.danielteng.com
12年2月25日星期六
Refactoring
              www.danielteng.com
12年2月25日星期六
Test One Class
                               File             DOC
                              System                                          CPU
                                                                            Intensive
                                                Seam
                                                  Call
                                                   Dependency on
                                                    Component
                                                                      DOC
                     Test Fixture                                        Subject Under Test
                                                                                Destructive
                                                      Dependency on
                                                  Assert
                                                       Component
                                                                                Operations

                                                                      DOC

                                                                                               Other
                                                      Dependency on                           Services
                                                       Component
       Object Lifetime and Calling
                          Object Instantiated



                           Object Passed In

                                    www.danielteng.com                Revised from Misko Hevery

                           Global Object
12年2月25日星期六
Test Fixture
              www.danielteng.com
12年2月25日星期六
Mixing Object
              Constructions with Logic



                 Object graph Business Logic
                 constructions and
                 looking for




                     www.danielteng.com
12年2月25日星期六
Two Piles of Logic
              • Construction logic     • Business logic
                • Factory
                • Inversion of
                  Control




                            www.danielteng.com
12年2月25日星期六
Boy Scout Rule: “Leave the campground
                    cleaner than you found it.”
                       www.danielteng.com
12年2月25日星期六
Strategies Dealing with Legacy

              • Build safe net by adding functional tests to
                cover all business logic
              • Move logic unit to its home and protect it
                with tests
              • Break dependencies by introducing seam
              • Replace functional tests with unit tests
         The Rule: FEEDBACK based on
                     Safe Steps
                 www.danielteng.com
                        SMALL
12年2月25日星期六
Now It is Up To YOU
                  www.danielteng.com
12年2月25日星期六
Now It is Up To YOU
                  www.danielteng.com
12年2月25日星期六
Thanks


              www.danielteng.com
12年2月25日星期六

Más contenido relacionado

Más de topgeek

项亮 推荐系统实践 从入门到精通
项亮 推荐系统实践 从入门到精通 项亮 推荐系统实践 从入门到精通
项亮 推荐系统实践 从入门到精通 topgeek
 
空望 推荐系统@淘宝
空望 推荐系统@淘宝空望 推荐系统@淘宝
空望 推荐系统@淘宝topgeek
 
从长津湖战役看团队建设
从长津湖战役看团队建设从长津湖战役看团队建设
从长津湖战役看团队建设topgeek
 
Agile changes in liba
Agile changes in libaAgile changes in liba
Agile changes in libatopgeek
 
百姓网的网速优化之路
百姓网的网速优化之路百姓网的网速优化之路
百姓网的网速优化之路topgeek
 
Ruby agile development_of_game_operation_platform
Ruby agile development_of_game_operation_platformRuby agile development_of_game_operation_platform
Ruby agile development_of_game_operation_platformtopgeek
 
图形组件技术杂谈
图形组件技术杂谈图形组件技术杂谈
图形组件技术杂谈topgeek
 
Rest与面向资源的web开发
Rest与面向资源的web开发Rest与面向资源的web开发
Rest与面向资源的web开发topgeek
 
腾讯大讲堂42 数据库内核设计思路浅析
腾讯大讲堂42 数据库内核设计思路浅析腾讯大讲堂42 数据库内核设计思路浅析
腾讯大讲堂42 数据库内核设计思路浅析topgeek
 
腾讯大讲堂38 oracle基础体系结构及性能优化
腾讯大讲堂38 oracle基础体系结构及性能优化腾讯大讲堂38 oracle基础体系结构及性能优化
腾讯大讲堂38 oracle基础体系结构及性能优化topgeek
 
腾讯大讲堂48 数据库查询优化浅析
腾讯大讲堂48 数据库查询优化浅析腾讯大讲堂48 数据库查询优化浅析
腾讯大讲堂48 数据库查询优化浅析topgeek
 
腾讯大讲堂46 自由cgi之路v3
腾讯大讲堂46 自由cgi之路v3腾讯大讲堂46 自由cgi之路v3
腾讯大讲堂46 自由cgi之路v3topgeek
 
腾讯大讲堂26 带宽优化之道
腾讯大讲堂26 带宽优化之道腾讯大讲堂26 带宽优化之道
腾讯大讲堂26 带宽优化之道topgeek
 
腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍topgeek
 
腾讯大讲堂24 qq show2.0重构历程
腾讯大讲堂24 qq show2.0重构历程腾讯大讲堂24 qq show2.0重构历程
腾讯大讲堂24 qq show2.0重构历程topgeek
 
腾讯大讲堂19 系统优化的方向
腾讯大讲堂19 系统优化的方向腾讯大讲堂19 系统优化的方向
腾讯大讲堂19 系统优化的方向topgeek
 
腾讯大讲堂17 性能优化不是仅局限于后台(qzone)
腾讯大讲堂17 性能优化不是仅局限于后台(qzone)腾讯大讲堂17 性能优化不是仅局限于后台(qzone)
腾讯大讲堂17 性能优化不是仅局限于后台(qzone)topgeek
 
腾讯大讲堂13 soso访问速度优化
腾讯大讲堂13 soso访问速度优化腾讯大讲堂13 soso访问速度优化
腾讯大讲堂13 soso访问速度优化topgeek
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站topgeek
 
腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨topgeek
 

Más de topgeek (20)

项亮 推荐系统实践 从入门到精通
项亮 推荐系统实践 从入门到精通 项亮 推荐系统实践 从入门到精通
项亮 推荐系统实践 从入门到精通
 
空望 推荐系统@淘宝
空望 推荐系统@淘宝空望 推荐系统@淘宝
空望 推荐系统@淘宝
 
从长津湖战役看团队建设
从长津湖战役看团队建设从长津湖战役看团队建设
从长津湖战役看团队建设
 
Agile changes in liba
Agile changes in libaAgile changes in liba
Agile changes in liba
 
百姓网的网速优化之路
百姓网的网速优化之路百姓网的网速优化之路
百姓网的网速优化之路
 
Ruby agile development_of_game_operation_platform
Ruby agile development_of_game_operation_platformRuby agile development_of_game_operation_platform
Ruby agile development_of_game_operation_platform
 
图形组件技术杂谈
图形组件技术杂谈图形组件技术杂谈
图形组件技术杂谈
 
Rest与面向资源的web开发
Rest与面向资源的web开发Rest与面向资源的web开发
Rest与面向资源的web开发
 
腾讯大讲堂42 数据库内核设计思路浅析
腾讯大讲堂42 数据库内核设计思路浅析腾讯大讲堂42 数据库内核设计思路浅析
腾讯大讲堂42 数据库内核设计思路浅析
 
腾讯大讲堂38 oracle基础体系结构及性能优化
腾讯大讲堂38 oracle基础体系结构及性能优化腾讯大讲堂38 oracle基础体系结构及性能优化
腾讯大讲堂38 oracle基础体系结构及性能优化
 
腾讯大讲堂48 数据库查询优化浅析
腾讯大讲堂48 数据库查询优化浅析腾讯大讲堂48 数据库查询优化浅析
腾讯大讲堂48 数据库查询优化浅析
 
腾讯大讲堂46 自由cgi之路v3
腾讯大讲堂46 自由cgi之路v3腾讯大讲堂46 自由cgi之路v3
腾讯大讲堂46 自由cgi之路v3
 
腾讯大讲堂26 带宽优化之道
腾讯大讲堂26 带宽优化之道腾讯大讲堂26 带宽优化之道
腾讯大讲堂26 带宽优化之道
 
腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍
 
腾讯大讲堂24 qq show2.0重构历程
腾讯大讲堂24 qq show2.0重构历程腾讯大讲堂24 qq show2.0重构历程
腾讯大讲堂24 qq show2.0重构历程
 
腾讯大讲堂19 系统优化的方向
腾讯大讲堂19 系统优化的方向腾讯大讲堂19 系统优化的方向
腾讯大讲堂19 系统优化的方向
 
腾讯大讲堂17 性能优化不是仅局限于后台(qzone)
腾讯大讲堂17 性能优化不是仅局限于后台(qzone)腾讯大讲堂17 性能优化不是仅局限于后台(qzone)
腾讯大讲堂17 性能优化不是仅局限于后台(qzone)
 
腾讯大讲堂13 soso访问速度优化
腾讯大讲堂13 soso访问速度优化腾讯大讲堂13 soso访问速度优化
腾讯大讲堂13 soso访问速度优化
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
 
腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨
 

I hate unit test

  • 1. I Hate Unit Test!!! Daniel Teng, Certified Scrum Coach www.danielteng.com 12年2月25日星期六
  • 2. A Brand-new Legacy Project www.danielteng.com 12年2月25日星期六
  • 3. The Pain Point www.danielteng.com 12年2月25日星期六
  • 4. AccountService.LogOn(LogOnModel model) www.danielteng.com 12年2月25日星期六
  • 5. The Logic Flow www.danielteng.com 12年2月25日星期六
  • 6. Broken Window www.danielteng.com 12年2月25日星期六
  • 7. Misko Hevery Test Iceberg www.danielteng.com 12年2月25日星期六
  • 8. But, What is Unit Test Anyway? www.danielteng.com 12年2月25日星期六
  • 9. A Test is NOT a Unit Test If: • It talks to the database • It communicates across the network • It touches the file system • It can't run at the same time as any of your other unit tests • You have to do special things to your environment (such as editing config files) to run it. www.danielteng.com 12年2月25日星期六
  • 10. I will do UT when I start a green field project • Legacy codebase • UI is not testable • It is QA’s job • It doesn’t catch bug • Too many dependencies Real Reason change, I will have • It double effort because when code to change tests too. I don’t know how to write!!! www.danielteng.com 12年2月25日星期六
  • 11. Refactoring www.danielteng.com 12年2月25日星期六
  • 12. Test One Class File DOC System CPU Intensive Seam Call Dependency on Component DOC Test Fixture Subject Under Test Destructive Dependency on Assert Component Operations DOC Other Dependency on Services Component Object Lifetime and Calling Object Instantiated Object Passed In www.danielteng.com Revised from Misko Hevery Global Object 12年2月25日星期六
  • 13. Test Fixture www.danielteng.com 12年2月25日星期六
  • 14. Mixing Object Constructions with Logic Object graph Business Logic constructions and looking for www.danielteng.com 12年2月25日星期六
  • 15. Two Piles of Logic • Construction logic • Business logic • Factory • Inversion of Control www.danielteng.com 12年2月25日星期六
  • 16. Boy Scout Rule: “Leave the campground cleaner than you found it.” www.danielteng.com 12年2月25日星期六
  • 17. Strategies Dealing with Legacy • Build safe net by adding functional tests to cover all business logic • Move logic unit to its home and protect it with tests • Break dependencies by introducing seam • Replace functional tests with unit tests The Rule: FEEDBACK based on Safe Steps www.danielteng.com SMALL 12年2月25日星期六
  • 18. Now It is Up To YOU www.danielteng.com 12年2月25日星期六
  • 19. Now It is Up To YOU www.danielteng.com 12年2月25日星期六
  • 20. Thanks www.danielteng.com 12年2月25日星期六