More Related Content Similar to リファクタリング読書会20120220
Similar to リファクタリング読書会20120220 (20) リファクタリング読書会201202209. class FileReaderTester extends TestCase . . .
protected void setUp() {
try {
_input = new FileReader(“data.txt”);
} catch (FileNotFoundException e) {
throw new RuntimeException();
}
}
protected void tearDown() {
try {
_input.close();
} catch (FileNotFoundException e) {
throw new RuntimeException();
}
}
11. class FileReaderTester . . .
protected void testRead() throw IOException {
char ch = ‘&’;
for (int i = 0; i < 4; i++)
ch = (char) _input.read();
assert(‘d’ == ch);
}
13. class FileReaderTester . . .
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new FileReaderTester(“testRead”));
return suite;
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
15. class FileReaderTester . . .
protected void testRead() throw IOException {
char ch = ‘&’;
for (int i = 0; i < 4; i++)
ch = (char) _input.read();
assert(‘2’ == ch); //故意のエラー
}
18. 単体テストと機能テスト
• 単体テスト:プログラマの生産性を向上する
ため
• 機能テスト:ソフトウェア全体の動作を保証
するため
19. バグを発見したら
• まずはバグを明らかにするための単体テスト
を書くべき
• バグを突き止めるのにも、再度おなじバグ
が単体テストをすり抜けないことを保証す
るのにも役立つ
21. やめ時はいつか
• 過剰なテスト
• やる気が失せて、何も書けずに終わる危険
• リスクがどこにあるか注目すべき
• コードを見て、複雑になってくるところ
• 機能をみて、エラーが起こりそうなところ
Editor's Notes \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n