0
はたとえば、このクラス:他のメソッドを呼び出さずに、ジャスミンとテストメソッドで単体テストを書く方法は?
export class List<T> {
private _count: number;
private _items: Array<T>;
constructor() {
this._count = 0;
this._items = [];
}
get(index: number) {
return this._items[index];
}
add(item: T) {
this._items[this._count] = item;
this._count++;
}
}
ジャスミンのこのユニットテスト:
import { List } from './list';
describe('List',() => {
let testList: List<string>;
beforeEach(() => {
testList = new List<string>();
});
it('get() method works',() => {
//how to test get() method without calling add() method?
testList.add("string1");
testList.add("string2");
testList.add("string3");
let s1: string = testList.get(0);
let s2: string = testList.get(1);
let s3: string = testList.get(2);
expect(s1).toBe("string1");
expect(s2).toBe("string2");
expect(s3).toBe("string3");
});
}
私が思うには、これはユニットテストが、統合テストではありませんので、右のユニットテストを書く方法?私は偽物を見るが、私はこの場合にどのように使用するのか分からない。