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
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
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
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
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
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