0
,이 클래스 : 재스민의다른 방법을 호출하지 않고 jasmine과 test method에서 단위 테스트를 작성하는 방법은 무엇입니까? 예를 들어
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");
});
}
내 생각이 아니다 단위 테스트하지만, 통합 테스트, 그래서 얼마나 잘 단위 테스트를 작성? 나는 모의를 본다. 그러나 나는이 경우 그것을 사용하는 방법을 모른다.