SlideShare une entreprise Scribd logo
1  sur  67
Télécharger pour lire hors ligne
Software Development for Large
      and Open Source Projects
                    Kun-Ta Chuang
Department of Computer Science and Information Engineering
              National Cheng Kung University



                                                             1
Software Development
                Foundation I
                    Kun-Ta Chuang
Department of Computer Science and Information Engineering
              National Cheng Kung University



                                                             2
Revision Control




                   3
• 版本控制(Revision control)
  – 維護工程藍圖的標準作法
  – 能追蹤工程藍圖從誕生一直到定案的過程
  – 軟體工程技巧,藉此能在軟體開發的過程中,
    確保由不同人所編輯的同一程式檔案都得到同
    步




                           4
概述
• 透過文檔控制(documentation control),
  能記錄任何工程專案內各個模組的改動歷
  程,並為每次改動編上序號
• 一種簡單的版本控制形式如下:賦予初版
  一個版本等級「A」。做了第一次改變後,
  版本等級改為「B」,以此類推。最簡單的
  例子是,最初的版本指定為「1」,當做了
  改變之後,版本編號增加為「2」,以此類
  推。

                                   5
概述
• 版本控制能提供專案的設計者,將設計回
  復到之前任一狀態,這特性在設計過程中,
  碰到完全無法運作的情況時,非常重要




                    6
軟體版本控制
• 有時候,一個程式同時存有兩個
  以上的版本也有其必要性
 – 例如:在一個為了部署的版本中程
   式錯誤已經被修正、但沒有加入新
   功能;在另一個開發版本則有新的
   功能正在開發、也有新的錯誤待解
   決,這使得同時間需要不同的版本
   並修改


                     7
軟體版本的控制方法
• 最簡單的版本控制就是保留軟體不同版本
  的數份copy,並且適當編號。許多大型開發
  案都是使用這種簡單技巧
 – 雖然這種方法能用,但是很沒效率
  • 因為保存的數份copy幾乎完全一樣
  • 因為這種方法要高度依靠開發者的自我紀律,而常
    導致錯誤




                             8
軟體版本的控制方法
• 因此,有人開發出了將部份或全部版本控
  制工作自動化的版本控制系統。
• Delta encoding
 – 大部份的版本控制軟體採用Delta encoding:只
   保留檔案相繼版本之間的差異,這個方法可以
   更有效的儲存數個版本的檔案。




                                  9
中央式系統 VS 分散式系統
• 中央式系統
 – 由中央權威管理存取權限;或是像分散式系統
   容許多個單位同時進行,包括同時更動同一檔
   案。
 – 傳統上版本控制系統都是採用中央式系統:所
   有版本控制的工作在一個伺服器進行,由中央
   權威管理存取權限「鎖上」檔案庫中的檔案,
   一次只讓一個開發者工作


                          10
• 分散式系統
 – 開發者直接在各自的本地檔案庫工作,並容許多個
   開發者同時更動同一檔案,而各個檔案庫有另一個
   合併各個改變的功能。這個方式讓開發者能不靠網
   路也能繼續工作,也讓開發者有充分的版本控制能
   力,而不需經中央權威許可。分散式系統仍然可以
   有檔案上鎖功能。
 – 分散式系統Linux kernel的發明人Linus Benedict
   Torvalds就是分散式版本控制系統的支持者,他開
   發了目前被開源社群廣泛使用的分散式版本控制系
   統Git

                                     11
著名的版本控制軟體
•   BitKeeper
•   CVS(Concurrent Versions System)
•   Micorosoft Visual SourceSafe
•   Perforce
•   Rational ClearCase
•   RCS(GNU Revision Control System)
•   Serena Dimention
•   Subversion
•   SVK
•   Git
•   en:Monotone (software)
•   en:Bazaar (software)
•   Mercurial
•   en:SourceGear Vault


                                       12
Eclipse+Git




              13
Initial Setup
• 首先請先下載eclipse
 – Eclipse IDE for Java Developers
• 若下載其他版本看不到Git
 – Help>Install New Software>add
 – http://download.eclipse.org/egit/updates
 – 貼上以上網址即可安裝EGit




                                              14
(cont.)




          15
(cont.)




          16
(cont.)




          17
Check out




            18
Check out




http://code.google.com/hosting/   19
(cont.)




          20
(cont.)




          21
(cont.)




          22
(cont.)




          23
(cont.)




          24
(cont.)




          25
(cont.)




          26
Check in




           27
Commit




         28
(cont.)




          29
Push to Upstream




                   30
(cont.)




          31
(cont.)




          32
Finish




         33
Reference
• http://en.wikipedia.org/wiki/Revision_control




                                              34
Unit testing




               35
Outline
•   Let’s talk about Testing
•   What is unit testing?
•   Properties of a Unit Test
•   Why Unit Test?
•   Why not Unit Test?
•   List of unit testing frameworks



                                      36
Testing
• 測試的方法            測試的階段
 – 黑箱測試             ◦   單元測試
                    ◦   整合測試
 – 白箱測試
                    ◦   系統測試
• 測試的類型             ◦   回歸測試
 – 功能測試
 – 系統測試
 – 邊界值測試
 – 效能測試
 – 壓力測試

                               37
What is unit testing?
• 單元測試是針對程式單元來進行正確性檢驗的測試工作
• 程式單元
 – 通常,一個程式單元就是單個程式、函式等
 – 對於物件導向語言來說,最小的單元就是method
• 測試案例
 – 每個理想的測試案例都應該獨立於其他案例
• 單元測試通常由開發人員編寫,可以手動測試,或是做為
  建構自動化的一部分
 – 以java來說…
   • 結合Ant:     建立建構環境與自動化執行的工具。
   • 結合Maven: 提供建構環境、慣例與相依管理的工具。
   • 通通包在CI中


                                   38
Properties of a Unit Test
• Isolated
  – 沒必要為了測試輪胎而買台車子
• Repeatable
  – Tests 不能依賴於執行環境,每個developer都應該
    要可以run
• Fast
  – 單元測試的時間較短、快
• Self-Documenting
  – Testable code is clear and easy to follow
  – 不需要特別解釋元件如何執行,只需要看測試怎麼
    跑即可

                                            39
Why Unit Test?
• Debugging很花時間
• 當一個新的功能被加進來時,我們要如何
  確定舊的不會受到影響?
• 從Unit Test你可以看出這個class的功能為何
  以及如何使用
• Unit Test可以用來量測project的健康度與
  code的品質


                                40
Why not Unit Test?
•   寫code從來沒有bug
•   功能都超簡單
•   寫測試會大幅拖累我的進度
•   PM不讓我寫
•   我不會寫…




                            41
List of unit testing frameworks
• 各種程式語言都有適合的單元測試工具可
  以使用
 – Java
 – C/C++
 – .NET
 – PHP
 – HTML



                                   42
Unit Testing Frameworks

 • Java
工具名稱            說明
JUnit     一個以逆向
          Framework測試的
          Java試工具,開發人
          員可用來進行Java的
          單元測試。
JUnitEE   JUnit的延伸版,可
          在J2EE Application
          Server上執行。
JMock     一個用於Java測試的
          函式庫,可快速的定
          義合適模擬物件。
                                  43
Unit Testing Frameworks
• C/C++
工具名稱            說明
C unit    以節點的方式測試系
          統,是一以專為C語
Test      言設計的測試工具。
System
Cgreen    一個純C單元測試工
          具,整合了測試套件,
          對於結果及建立新的
          測試函數有很大的彈
          性。
CMock     支援模組式/物件式
          的測試工具,以交談
          試的方式進行單元測
          試。        圖片來源: http://www.lastcraft.com/cgreen.php
                                                       44
Unit Testing Frameworks

• .Net

工具名稱             說明
ASP Unit   Microsoft Active
           Server Pages (ASP)
           測試工具。
csUnit     支援C# , VB .Net ,
           managed C++ 。
.NetUnit   對圖形元件進行測
           試的工具。



                                圖片來源: http://www.csunit.org/
                                                         45
Unit Testing Frameworks

 • PHP


工具名稱           說明
PHPUnit PHP4專用,適用於
         輕量的軟體開發。
AMock    由EasyMock而來的
         函式庫。
Izh_test 可在Console底下進
         行php的測試。
                                                           46
              圖片來源: http://php-gtk.eu/en/version/php-gtk-2?page=8
Unit Testing Frameworks

 • HTML
  工具名稱            說明
HTML Tidy      可完美的自動
               修正Html的語
               法錯誤。
HtmlTestCase   支援使用高階
               的API進行自
               動的功能測試,
               試用於QA人員。
HtmlUnit       Junit的測試
               Framework之
               一。
                                47
Example-Junit
Unit test for class Calculator’s method plus:          Class Calculator:
        import static org.junit.Assert.*;              public class Calculator {
        import org.junit.*;                              public int plus(int op1, int op2) {
                                                           return op1 + op2;
        ………….
                                                         }
        public class CalculatorTest {                    public int minus(int op1, int op2) {
          private Calculator calculator;                   return op1 - op2;
          @Before                                        }
          public void setUp() {                        }
            calculator = new Calculator();                  當然,可以配合多種design
          }                                                pattern去設計你的test,像是
          @After                                                  Command…,etc
          public void tearDown() {
            calculator = null;
          }
          @Test
          public void testPlus() {                JUnit 4.x中,不用像3.x一般需要繼
            int expected = 5;                     承TestCase類別,而可以使用@Test
                                                  標註測試方法,方法只需公開、沒
            int result = calculator.plus(3, 2);   有傳回值、沒有參數,名稱則可以
            assertEquals(expected, result);                  任意。
          }
                                                                                                48
Example-Junit



       測試成功
                測試失敗




                       49
TDD( Test-driven development)
• 由測試去驅動開發功能
 – 在撰寫真正的程式碼前,先將相關測試寫好
• 並不是單純在做 verification,它是一種 spec
  確認的活動
 – 避免程式寫到最後,與最初的設計差別太大
• TDD全然關乎為特定功能做測試,接著,撰
  寫程式碼滿足該功能。
 – 任何超過該功能的事情,目前對你皆不重要
 – 避免浪費時間做了不必要的功能
                                  50
Reference
•   Head First Software Development
     – Dan Pilone & Russ Miles
•   http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
•   http://www.slideshare.net/avalanche123/clean-code-5609451
•   http://caterpillar.onlyfun.net/Gossip/JUnit/index.html
•   http://zh.wikipedia.org/wiki/%E8%BB%9F%E9%AB%94%E6%B8%AC%E8%A9%A6#.
    E8.BD.AF.E4.BB.B6.E6.B5.8B.E8.AF.95.E4.BB.8B.E7.BB.8D




                                                                     51
HW 1
• Upload your first code to public code host like google code host or github
    – With a small code without compilation errors
        • More than 100 lines ‘source’
        • More than 30 lines ‘comment’ to describe your source
    – With unit testing file
    – With a README informing how to execute unit testing for your code
• Evaluated by teams
    – Each team should have a HW1 contact window in charge of emailing to TA
        • 黃首翰 arvin0731@gmail.com
        • Tell TA where we can check out your code (if you use git, give the URL)
• Deadline 10/24 12:00 pm
    – if you did not get confirmed email from TA. We say
       byebye
       byebye
         …
       byebye~~
    – You should do it ASAP to ensure your success

                                                                                    52
HW 1
• Remind you
  – TAs will check your coding style
  – TAs won’t ask you if he cannot execute your code but
    fully comply with your README
  – The team score is the average score from 4 TAs.
     • Like an academic review process, if their scores are highly
       diverse, I will check and join to determine the score.
  – Just four levels
     •   Weak: 50
     •   Above Average: 70
     •   Good: 80
     •   Excellent: 100

                                                                     53
Build Automation
介紹
• 歷史
 – 一開始,於command line進行程式碼編譯及連
   結。
   • 程式碼一多就相當麻煩。
 – 出現make script language,如GUN make,為建
   置自動化的開始。
   • 支援多個程式模組編譯及連結。
 – 隨者建置過程複雜度的提升,便開始出現一些
   商業化或免費的自動建置軟體。
   • 對於Continuous Integration相當有幫助。
介紹
• 什麼是Build automation ?
• 將軟體設計師的每日工作,以自動化技術
  或腳本語言方式,自動加以完成的工具與
  技術。工作包含 :
 – 以編譯器將原始碼編譯成二進位碼( Binary code)
 – 將二進位碼打包成軟體執行檔
 – 執行單元測試
 – 部署軟體(Software deployment)
 – 產生文件與 Release notes
介紹
• 於專案軟體開發,使用Build automation 優
  點
 – 提升產品品質
 – 加快編譯及連結的效率
 – 減少“bad build”發生
 – 降低關鍵人員依賴性
 – 保留建置歷史記錄
 – 節省時間以及成本
相關工具介紹 - Ant
• Ant
  – Apache提供的免費軟體
  – 為command line工具,主要用來進行Java code
    的自動建置。
  – Script腳本主要用XML格式來撰寫
相關工具介紹 - Ant
• 以HelloWorld為範例進行編譯和執行




       Fig1 :以Hello world為例
相關工具介紹 - Ant
設定參數




 編譯



產生執行檔




 執行



          Fig2 :以Hello world為例,ant建置的腳本檔案Sample
相關工具介紹 - Ant




    Fig3 :以Hello world為例,ant建置結果
相關工具介紹 - Ant
• 以Math為範例進行Junit測試




       Fig4. 以Math為例,待測試的程式碼
相關工具介紹 - Ant




       Fig5. 以Math為例,測試案例撰寫
相關工具介紹 - Ant


進行
測試




產生
報表


       Fig6 :以Math為例,ant建置的腳本檔案Sample
相關工具介紹 - Ant




Fig7 :以Math為例,測試結果的報表
相關工具介紹 - Maven
• 和Ant一樣是專案自動化建置的工具
• 和Ant比較起來,Maven有以下額外功能 :
 – 集中管理相依性
   • Maven使用集中式管理,提供Central repository,你
     要在設定檔案宣告相依的程式庫等資訊,Maven會為
     你下載相關的檔案。
 – plugin 為基礎的架構
   • Maven 提供固定的建構生命周期,每個周期又有幾個
     階段,每個階段會有一些相連結的plugin,可以在設
     定檔中依需求宣告想使用的plugin,Maven會自動取
     得plugin。
參考資料
• Wiki Build automation
  http://en.wikipedia.org/wiki/Build_automation
• Tool - Apache Ant
  http://ant.apache.org
• Tool – Maven
  http://maven.apache.org/
• JUnit Gossip: 使用 Maven
• http://caterpillar.onlyfun.net/Gossip/JUnit/Maven.
  html

Contenu connexe

Tendances

Legacy code 讀書會 1st (Ch1 - Ch5)
Legacy code 讀書會 1st (Ch1 - Ch5)Legacy code 讀書會 1st (Ch1 - Ch5)
Legacy code 讀書會 1st (Ch1 - Ch5)Fong Liou
 
Testing survey
Testing surveyTesting survey
Testing surveyTao He
 
PHPUnit slide formal
PHPUnit slide formalPHPUnit slide formal
PHPUnit slide formaljameslabs
 
TDD (Test-driven development, 測試驅動開發) 基本教學
TDD (Test-driven development, 測試驅動開發) 基本教學TDD (Test-driven development, 測試驅動開發) 基本教學
TDD (Test-driven development, 測試驅動開發) 基本教學潘 冠辰
 
例外處理與單元測試
例外處理與單元測試例外處理與單元測試
例外處理與單元測試國昭 張
 
Duannian agile
Duannian agileDuannian agile
Duannian agiled0nn9n
 
service-oriented agile team-Q con-beijing2012
service-oriented agile team-Q con-beijing2012service-oriented agile team-Q con-beijing2012
service-oriented agile team-Q con-beijing2012Qiao Liang
 
例外處理實務
例外處理實務例外處理實務
例外處理實務Jeff Chu
 
Junit使用指南及作业规范
Junit使用指南及作业规范Junit使用指南及作业规范
Junit使用指南及作业规范dong jiang
 

Tendances (14)

Unit test
Unit testUnit test
Unit test
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
Legacy code 讀書會 1st (Ch1 - Ch5)
Legacy code 讀書會 1st (Ch1 - Ch5)Legacy code 讀書會 1st (Ch1 - Ch5)
Legacy code 讀書會 1st (Ch1 - Ch5)
 
單元測試
單元測試單元測試
單元測試
 
Testing survey
Testing surveyTesting survey
Testing survey
 
PHPUnit slide formal
PHPUnit slide formalPHPUnit slide formal
PHPUnit slide formal
 
TDD (Test-driven development, 測試驅動開發) 基本教學
TDD (Test-driven development, 測試驅動開發) 基本教學TDD (Test-driven development, 測試驅動開發) 基本教學
TDD (Test-driven development, 測試驅動開發) 基本教學
 
例外處理與單元測試
例外處理與單元測試例外處理與單元測試
例外處理與單元測試
 
Duannian agile
Duannian agileDuannian agile
Duannian agile
 
Xpp
XppXpp
Xpp
 
service-oriented agile team-Q con-beijing2012
service-oriented agile team-Q con-beijing2012service-oriented agile team-Q con-beijing2012
service-oriented agile team-Q con-beijing2012
 
例外處理實務
例外處理實務例外處理實務
例外處理實務
 
軟體工程(總結篇)
軟體工程(總結篇)軟體工程(總結篇)
軟體工程(總結篇)
 
Junit使用指南及作业规范
Junit使用指南及作业规范Junit使用指南及作业规范
Junit使用指南及作业规范
 

Similaire à Foundation of software development 1

敏捷测试中的工具实现
敏捷测试中的工具实现敏捷测试中的工具实现
敏捷测试中的工具实现drewz lin
 
广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdfbj_qa
 
豆瓣I os自动化测试实践和经验
豆瓣I os自动化测试实践和经验豆瓣I os自动化测试实践和经验
豆瓣I os自动化测试实践和经验drewz lin
 
Tcon分享 芈峮
Tcon分享 芈峮Tcon分享 芈峮
Tcon分享 芈峮mijun_hlp
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)Rick Hwang
 
Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...
Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...
Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...Yun-Lin Huang
 
Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Will Huang
 
Clipper@datacon.2019.tw
Clipper@datacon.2019.twClipper@datacon.2019.tw
Clipper@datacon.2019.twWei-Yu Chen
 
软件工程 第七章
软件工程 第七章软件工程 第七章
软件工程 第七章浒 刘
 
Se2009 ch8
Se2009 ch8 Se2009 ch8
Se2009 ch8 浒 刘
 
软件工程 第八章
软件工程 第八章软件工程 第八章
软件工程 第八章浒 刘
 
20121213 foundation of software development 2 2-ktchuang
20121213 foundation of software development 2 2-ktchuang20121213 foundation of software development 2 2-ktchuang
20121213 foundation of software development 2 2-ktchuangnetdbncku
 
Top100summit automan x之框架介绍 王超
Top100summit automan x之框架介绍 王超Top100summit automan x之框架介绍 王超
Top100summit automan x之框架介绍 王超drewz lin
 
Continuous Delivery: automated testing, continuous integration and continuous...
Continuous Delivery: automated testing, continuous integration and continuous...Continuous Delivery: automated testing, continuous integration and continuous...
Continuous Delivery: automated testing, continuous integration and continuous...Jimmy Lai
 
The way to continuous delivery
The way to continuous deliveryThe way to continuous delivery
The way to continuous deliveryQiao Liang
 
Angular Testing for Book Club Online of Angular Taiwan
Angular Testing for Book Club Online of Angular TaiwanAngular Testing for Book Club Online of Angular Taiwan
Angular Testing for Book Club Online of Angular Taiwan志龍 陳
 
同济优秀课程设计 - 软件测试报告
同济优秀课程设计 - 软件测试报告同济优秀课程设计 - 软件测试报告
同济优秀课程设计 - 软件测试报告Kerry Zhu
 
C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4Tao He
 

Similaire à Foundation of software development 1 (20)

敏捷测试中的工具实现
敏捷测试中的工具实现敏捷测试中的工具实现
敏捷测试中的工具实现
 
广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf
 
豆瓣I os自动化测试实践和经验
豆瓣I os自动化测试实践和经验豆瓣I os自动化测试实践和经验
豆瓣I os自动化测试实践和经验
 
Tcon分享 芈峮
Tcon分享 芈峮Tcon分享 芈峮
Tcon分享 芈峮
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
 
Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...
Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...
Overview of Qt/QtQuick Testing, and Study for Qt GUI Automation Testing by Qt...
 
Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)
 
Clipper@datacon.2019.tw
Clipper@datacon.2019.twClipper@datacon.2019.tw
Clipper@datacon.2019.tw
 
软件工程 第七章
软件工程 第七章软件工程 第七章
软件工程 第七章
 
Se2009 ch8
Se2009 ch8 Se2009 ch8
Se2009 ch8
 
软件工程 第八章
软件工程 第八章软件工程 第八章
软件工程 第八章
 
20121213 foundation of software development 2 2-ktchuang
20121213 foundation of software development 2 2-ktchuang20121213 foundation of software development 2 2-ktchuang
20121213 foundation of software development 2 2-ktchuang
 
Top100summit automan x之框架介绍 王超
Top100summit automan x之框架介绍 王超Top100summit automan x之框架介绍 王超
Top100summit automan x之框架介绍 王超
 
Continuous Delivery: automated testing, continuous integration and continuous...
Continuous Delivery: automated testing, continuous integration and continuous...Continuous Delivery: automated testing, continuous integration and continuous...
Continuous Delivery: automated testing, continuous integration and continuous...
 
The way to continuous delivery
The way to continuous deliveryThe way to continuous delivery
The way to continuous delivery
 
Python系列1
Python系列1Python系列1
Python系列1
 
Angular Testing for Book Club Online of Angular Taiwan
Angular Testing for Book Club Online of Angular TaiwanAngular Testing for Book Club Online of Angular Taiwan
Angular Testing for Book Club Online of Angular Taiwan
 
LabView with Lego NXT
LabView  with Lego NXTLabView  with Lego NXT
LabView with Lego NXT
 
同济优秀课程设计 - 软件测试报告
同济优秀课程设计 - 软件测试报告同济优秀课程设计 - 软件测试报告
同济优秀课程设计 - 软件测试报告
 
C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4
 

Plus de netdbncku

Jenkins hand in hand
Jenkins  hand in handJenkins  hand in hand
Jenkins hand in handnetdbncku
 
20121213 qa introduction smileryang
20121213 qa introduction smileryang20121213 qa introduction smileryang
20121213 qa introduction smileryangnetdbncku
 
Software development lifecycle_release_management
Software development lifecycle_release_managementSoftware development lifecycle_release_management
Software development lifecycle_release_managementnetdbncku
 
2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai su
2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai su2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai su
2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai sunetdbncku
 
Intoduction of programming contest
Intoduction of programming contestIntoduction of programming contest
Intoduction of programming contestnetdbncku
 
Tutorial of eclipse
Tutorial of eclipseTutorial of eclipse
Tutorial of eclipsenetdbncku
 
3. java basics
3. java basics3. java basics
3. java basicsnetdbncku
 
2. java introduction
2. java introduction2. java introduction
2. java introductionnetdbncku
 

Plus de netdbncku (8)

Jenkins hand in hand
Jenkins  hand in handJenkins  hand in hand
Jenkins hand in hand
 
20121213 qa introduction smileryang
20121213 qa introduction smileryang20121213 qa introduction smileryang
20121213 qa introduction smileryang
 
Software development lifecycle_release_management
Software development lifecycle_release_managementSoftware development lifecycle_release_management
Software development lifecycle_release_management
 
2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai su
2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai su2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai su
2012 11-16 cloud practices-in_trend_micro_2012 - chung-tsai su
 
Intoduction of programming contest
Intoduction of programming contestIntoduction of programming contest
Intoduction of programming contest
 
Tutorial of eclipse
Tutorial of eclipseTutorial of eclipse
Tutorial of eclipse
 
3. java basics
3. java basics3. java basics
3. java basics
 
2. java introduction
2. java introduction2. java introduction
2. java introduction
 

Foundation of software development 1

  • 1. Software Development for Large and Open Source Projects Kun-Ta Chuang Department of Computer Science and Information Engineering National Cheng Kung University 1
  • 2. Software Development Foundation I Kun-Ta Chuang Department of Computer Science and Information Engineering National Cheng Kung University 2
  • 4. • 版本控制(Revision control) – 維護工程藍圖的標準作法 – 能追蹤工程藍圖從誕生一直到定案的過程 – 軟體工程技巧,藉此能在軟體開發的過程中, 確保由不同人所編輯的同一程式檔案都得到同 步 4
  • 5. 概述 • 透過文檔控制(documentation control), 能記錄任何工程專案內各個模組的改動歷 程,並為每次改動編上序號 • 一種簡單的版本控制形式如下:賦予初版 一個版本等級「A」。做了第一次改變後, 版本等級改為「B」,以此類推。最簡單的 例子是,最初的版本指定為「1」,當做了 改變之後,版本編號增加為「2」,以此類 推。 5
  • 6. 概述 • 版本控制能提供專案的設計者,將設計回 復到之前任一狀態,這特性在設計過程中, 碰到完全無法運作的情況時,非常重要 6
  • 7. 軟體版本控制 • 有時候,一個程式同時存有兩個 以上的版本也有其必要性 – 例如:在一個為了部署的版本中程 式錯誤已經被修正、但沒有加入新 功能;在另一個開發版本則有新的 功能正在開發、也有新的錯誤待解 決,這使得同時間需要不同的版本 並修改 7
  • 8. 軟體版本的控制方法 • 最簡單的版本控制就是保留軟體不同版本 的數份copy,並且適當編號。許多大型開發 案都是使用這種簡單技巧 – 雖然這種方法能用,但是很沒效率 • 因為保存的數份copy幾乎完全一樣 • 因為這種方法要高度依靠開發者的自我紀律,而常 導致錯誤 8
  • 9. 軟體版本的控制方法 • 因此,有人開發出了將部份或全部版本控 制工作自動化的版本控制系統。 • Delta encoding – 大部份的版本控制軟體採用Delta encoding:只 保留檔案相繼版本之間的差異,這個方法可以 更有效的儲存數個版本的檔案。 9
  • 10. 中央式系統 VS 分散式系統 • 中央式系統 – 由中央權威管理存取權限;或是像分散式系統 容許多個單位同時進行,包括同時更動同一檔 案。 – 傳統上版本控制系統都是採用中央式系統:所 有版本控制的工作在一個伺服器進行,由中央 權威管理存取權限「鎖上」檔案庫中的檔案, 一次只讓一個開發者工作 10
  • 11. • 分散式系統 – 開發者直接在各自的本地檔案庫工作,並容許多個 開發者同時更動同一檔案,而各個檔案庫有另一個 合併各個改變的功能。這個方式讓開發者能不靠網 路也能繼續工作,也讓開發者有充分的版本控制能 力,而不需經中央權威許可。分散式系統仍然可以 有檔案上鎖功能。 – 分散式系統Linux kernel的發明人Linus Benedict Torvalds就是分散式版本控制系統的支持者,他開 發了目前被開源社群廣泛使用的分散式版本控制系 統Git 11
  • 12. 著名的版本控制軟體 • BitKeeper • CVS(Concurrent Versions System) • Micorosoft Visual SourceSafe • Perforce • Rational ClearCase • RCS(GNU Revision Control System) • Serena Dimention • Subversion • SVK • Git • en:Monotone (software) • en:Bazaar (software) • Mercurial • en:SourceGear Vault 12
  • 14. Initial Setup • 首先請先下載eclipse – Eclipse IDE for Java Developers • 若下載其他版本看不到Git – Help>Install New Software>add – http://download.eclipse.org/egit/updates – 貼上以上網址即可安裝EGit 14
  • 15. (cont.) 15
  • 16. (cont.) 16
  • 17. (cont.) 17
  • 18. Check out 18
  • 20. (cont.) 20
  • 21. (cont.) 21
  • 22. (cont.) 22
  • 23. (cont.) 23
  • 24. (cont.) 24
  • 25. (cont.) 25
  • 26. (cont.) 26
  • 27. Check in 27
  • 28. Commit 28
  • 29. (cont.) 29
  • 31. (cont.) 31
  • 32. (cont.) 32
  • 33. Finish 33
  • 36. Outline • Let’s talk about Testing • What is unit testing? • Properties of a Unit Test • Why Unit Test? • Why not Unit Test? • List of unit testing frameworks 36
  • 37. Testing • 測試的方法  測試的階段 – 黑箱測試 ◦ 單元測試 ◦ 整合測試 – 白箱測試 ◦ 系統測試 • 測試的類型 ◦ 回歸測試 – 功能測試 – 系統測試 – 邊界值測試 – 效能測試 – 壓力測試 37
  • 38. What is unit testing? • 單元測試是針對程式單元來進行正確性檢驗的測試工作 • 程式單元 – 通常,一個程式單元就是單個程式、函式等 – 對於物件導向語言來說,最小的單元就是method • 測試案例 – 每個理想的測試案例都應該獨立於其他案例 • 單元測試通常由開發人員編寫,可以手動測試,或是做為 建構自動化的一部分 – 以java來說… • 結合Ant: 建立建構環境與自動化執行的工具。 • 結合Maven: 提供建構環境、慣例與相依管理的工具。 • 通通包在CI中 38
  • 39. Properties of a Unit Test • Isolated – 沒必要為了測試輪胎而買台車子 • Repeatable – Tests 不能依賴於執行環境,每個developer都應該 要可以run • Fast – 單元測試的時間較短、快 • Self-Documenting – Testable code is clear and easy to follow – 不需要特別解釋元件如何執行,只需要看測試怎麼 跑即可 39
  • 40. Why Unit Test? • Debugging很花時間 • 當一個新的功能被加進來時,我們要如何 確定舊的不會受到影響? • 從Unit Test你可以看出這個class的功能為何 以及如何使用 • Unit Test可以用來量測project的健康度與 code的品質 40
  • 41. Why not Unit Test? • 寫code從來沒有bug • 功能都超簡單 • 寫測試會大幅拖累我的進度 • PM不讓我寫 • 我不會寫… 41
  • 42. List of unit testing frameworks • 各種程式語言都有適合的單元測試工具可 以使用 – Java – C/C++ – .NET – PHP – HTML 42
  • 43. Unit Testing Frameworks • Java 工具名稱 說明 JUnit 一個以逆向 Framework測試的 Java試工具,開發人 員可用來進行Java的 單元測試。 JUnitEE JUnit的延伸版,可 在J2EE Application Server上執行。 JMock 一個用於Java測試的 函式庫,可快速的定 義合適模擬物件。 43
  • 44. Unit Testing Frameworks • C/C++ 工具名稱 說明 C unit 以節點的方式測試系 統,是一以專為C語 Test 言設計的測試工具。 System Cgreen 一個純C單元測試工 具,整合了測試套件, 對於結果及建立新的 測試函數有很大的彈 性。 CMock 支援模組式/物件式 的測試工具,以交談 試的方式進行單元測 試。 圖片來源: http://www.lastcraft.com/cgreen.php 44
  • 45. Unit Testing Frameworks • .Net 工具名稱 說明 ASP Unit Microsoft Active Server Pages (ASP) 測試工具。 csUnit 支援C# , VB .Net , managed C++ 。 .NetUnit 對圖形元件進行測 試的工具。 圖片來源: http://www.csunit.org/ 45
  • 46. Unit Testing Frameworks • PHP 工具名稱 說明 PHPUnit PHP4專用,適用於 輕量的軟體開發。 AMock 由EasyMock而來的 函式庫。 Izh_test 可在Console底下進 行php的測試。 46 圖片來源: http://php-gtk.eu/en/version/php-gtk-2?page=8
  • 47. Unit Testing Frameworks • HTML 工具名稱 說明 HTML Tidy 可完美的自動 修正Html的語 法錯誤。 HtmlTestCase 支援使用高階 的API進行自 動的功能測試, 試用於QA人員。 HtmlUnit Junit的測試 Framework之 一。 47
  • 48. Example-Junit Unit test for class Calculator’s method plus: Class Calculator: import static org.junit.Assert.*; public class Calculator { import org.junit.*; public int plus(int op1, int op2) { return op1 + op2; …………. } public class CalculatorTest { public int minus(int op1, int op2) { private Calculator calculator; return op1 - op2; @Before } public void setUp() { } calculator = new Calculator(); 當然,可以配合多種design } pattern去設計你的test,像是 @After Command…,etc public void tearDown() { calculator = null; } @Test public void testPlus() { JUnit 4.x中,不用像3.x一般需要繼 int expected = 5; 承TestCase類別,而可以使用@Test 標註測試方法,方法只需公開、沒 int result = calculator.plus(3, 2); 有傳回值、沒有參數,名稱則可以 assertEquals(expected, result); 任意。 } 48
  • 49. Example-Junit 測試成功 測試失敗 49
  • 50. TDD( Test-driven development) • 由測試去驅動開發功能 – 在撰寫真正的程式碼前,先將相關測試寫好 • 並不是單純在做 verification,它是一種 spec 確認的活動 – 避免程式寫到最後,與最初的設計差別太大 • TDD全然關乎為特定功能做測試,接著,撰 寫程式碼滿足該功能。 – 任何超過該功能的事情,目前對你皆不重要 – 避免浪費時間做了不必要的功能 50
  • 51. Reference • Head First Software Development – Dan Pilone & Russ Miles • http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks • http://www.slideshare.net/avalanche123/clean-code-5609451 • http://caterpillar.onlyfun.net/Gossip/JUnit/index.html • http://zh.wikipedia.org/wiki/%E8%BB%9F%E9%AB%94%E6%B8%AC%E8%A9%A6#. E8.BD.AF.E4.BB.B6.E6.B5.8B.E8.AF.95.E4.BB.8B.E7.BB.8D 51
  • 52. HW 1 • Upload your first code to public code host like google code host or github – With a small code without compilation errors • More than 100 lines ‘source’ • More than 30 lines ‘comment’ to describe your source – With unit testing file – With a README informing how to execute unit testing for your code • Evaluated by teams – Each team should have a HW1 contact window in charge of emailing to TA • 黃首翰 arvin0731@gmail.com • Tell TA where we can check out your code (if you use git, give the URL) • Deadline 10/24 12:00 pm – if you did not get confirmed email from TA. We say byebye byebye … byebye~~ – You should do it ASAP to ensure your success 52
  • 53. HW 1 • Remind you – TAs will check your coding style – TAs won’t ask you if he cannot execute your code but fully comply with your README – The team score is the average score from 4 TAs. • Like an academic review process, if their scores are highly diverse, I will check and join to determine the score. – Just four levels • Weak: 50 • Above Average: 70 • Good: 80 • Excellent: 100 53
  • 55. 介紹 • 歷史 – 一開始,於command line進行程式碼編譯及連 結。 • 程式碼一多就相當麻煩。 – 出現make script language,如GUN make,為建 置自動化的開始。 • 支援多個程式模組編譯及連結。 – 隨者建置過程複雜度的提升,便開始出現一些 商業化或免費的自動建置軟體。 • 對於Continuous Integration相當有幫助。
  • 56. 介紹 • 什麼是Build automation ? • 將軟體設計師的每日工作,以自動化技術 或腳本語言方式,自動加以完成的工具與 技術。工作包含 : – 以編譯器將原始碼編譯成二進位碼( Binary code) – 將二進位碼打包成軟體執行檔 – 執行單元測試 – 部署軟體(Software deployment) – 產生文件與 Release notes
  • 57. 介紹 • 於專案軟體開發,使用Build automation 優 點 – 提升產品品質 – 加快編譯及連結的效率 – 減少“bad build”發生 – 降低關鍵人員依賴性 – 保留建置歷史記錄 – 節省時間以及成本
  • 58. 相關工具介紹 - Ant • Ant – Apache提供的免費軟體 – 為command line工具,主要用來進行Java code 的自動建置。 – Script腳本主要用XML格式來撰寫
  • 59. 相關工具介紹 - Ant • 以HelloWorld為範例進行編譯和執行 Fig1 :以Hello world為例
  • 60. 相關工具介紹 - Ant 設定參數 編譯 產生執行檔 執行 Fig2 :以Hello world為例,ant建置的腳本檔案Sample
  • 61. 相關工具介紹 - Ant Fig3 :以Hello world為例,ant建置結果
  • 62. 相關工具介紹 - Ant • 以Math為範例進行Junit測試 Fig4. 以Math為例,待測試的程式碼
  • 63. 相關工具介紹 - Ant Fig5. 以Math為例,測試案例撰寫
  • 64. 相關工具介紹 - Ant 進行 測試 產生 報表 Fig6 :以Math為例,ant建置的腳本檔案Sample
  • 65. 相關工具介紹 - Ant Fig7 :以Math為例,測試結果的報表
  • 66. 相關工具介紹 - Maven • 和Ant一樣是專案自動化建置的工具 • 和Ant比較起來,Maven有以下額外功能 : – 集中管理相依性 • Maven使用集中式管理,提供Central repository,你 要在設定檔案宣告相依的程式庫等資訊,Maven會為 你下載相關的檔案。 – plugin 為基礎的架構 • Maven 提供固定的建構生命周期,每個周期又有幾個 階段,每個階段會有一些相連結的plugin,可以在設 定檔中依需求宣告想使用的plugin,Maven會自動取 得plugin。
  • 67. 參考資料 • Wiki Build automation http://en.wikipedia.org/wiki/Build_automation • Tool - Apache Ant http://ant.apache.org • Tool – Maven http://maven.apache.org/ • JUnit Gossip: 使用 Maven • http://caterpillar.onlyfun.net/Gossip/JUnit/Maven. html