寫了個類,要給別人用,會不會有bug?怎麼辦?測試一下。
用main方法測試好不好?不好!
1. 不能一起執行!
2. 大多數情況下需要人為的觀察輸出確定是否正確
重用測試,應付將來的實現的變化。
提高士氣,明確知道我的東西是沒問題的。
1. new project
2. 建立類
3. 建立testcase
1. assertthat
2. 使用hamcrest的匹配方法
a) 更自然
3. 示例
a) assertthat( n, allof(greaterthan(1), lessthan(15) ) );
assertthat( n, anyof( greaterthan(16), lessthan(8) ) );
assertthat( n, anything() );
assertthat( str, is( "bjsxt" ) );
assertthat( str, not( "bjxxt" ) );
b) assertthat( str,containsstring( "bjsxt" ) );
assertthat( str, endswith("bjsxt" ) );
assertthat( str, startswith( "bjsxt" ) );
assertthat( n, equalto( nexpected ) );
assertthat( str, equaltoignoringcase( "bjsxt" ) );
assertthat( str, equaltoignoringwhitespace( "bjsxt" ) );
c) assertthat( d, closeto( 3.0, 0.3) );
assertthat( d, greaterthan(3.0) );
assertthat( d, lessthan (10.0) );
assertthat( d, greaterthanorequalto (5.0) );
assertthat( d, lessthanorequalto (16.0) );
d) assertthat( map, hasentry("bjsxt", "bjsxt" ) );
assertthat( iterable, hasitem ( "bjsxt" ) );
assertthat( map, haskey ( "bjsxt" ) );
assertthat( map, hasvalue ( "bjsxt" ) );
1. failure是指測試失敗
2. error是指測試程式本身出錯
1. @test: 測試方法
a) (expected=xxexception.class)
b) (timeout=***)
2. @ignore: 被忽略的測試方法
3. @before: 每乙個測試方法之前執行
4. @after: 每乙個測試方法之後執行
5. @beforeclass: 所有測試開始之前執行
6. @afterclass: 所有測試結束之後執行
1. 遵守約定,比如:
a) 類放在test包中
b) 類名用***test結尾
c) 方法用testmethod命名
testng
JUNIT4 筆記(五) 測試套
測試套包含乙個或多個需要被一起執行的測試用例或測試套。測試套需要在類名前加 runwith suite.class 表示不使用預設的測試執行器,使用指定的測試執行器,在這裡suite.class就是指定的測試執行器。並用 suite.suiteclasses指定該測試套包含的其他測試用例或測試套。i...
JUnit4學習筆記1
在計算機程式設計中,單元測試 又稱為模組測試,unit testing 是針對程式模組 軟體設計的最小單位 來進行正確性檢驗的測試工作。程式單元是應用的最小可測試部件。對於物件導向程式設計,最小單元就是方法,包括基類 超類 抽象類 或者派生類 子類 中的方法。執行單元測試,是為了證明某段 的行為確實...
STM32筆記記錄4
user main.c 7 warning 223 d function iic busrtwrite declared implicitly 這個是因為程式模組化的時候,你在乙個.c裡面呼叫了另乙個.c的函式而沒有進行外部宣告。你將這個宣告的這個函式前面加上extern應該就好了!或者是函式宣告時...