Slide 3
Slide 3 text
何が嬉しいの?
● 単体テストがしやすくなる!
class Service {
private repository;
constructor() {
this.repository = new Repository();
}
find() {
// ...
this.repository.find();
return;
}
}
よくあるテストしにくい例
テストしたいのはService層のロジック
Repository(DB)のテストも含まれてしまう
・テスト失敗した時の切り分けが面倒
・実行時間がかかる
DI→テスト側からモックを注入できる!