04 - Dublerzy testowi
Click here to load reader
-
Upload
krzysztof-jelski -
Category
Entertainment & Humor
-
view
543 -
download
0
Transcript of 04 - Dublerzy testowi
DUBLERZY TESTOWI
1.Prezentacja kodu
2.Dublerzy - kiedy i po co?
3.Dummy
4.Stub
5.Mock
6.Spy
Prezentacja kodu
MOCKI
KLASYCZNE TESTOWANIE
SUTTEST
FIXTURE
Exercise
Verify
Setup
TEST Z ZALEŻNOŚCIĄ
SUT DOCTEST
FIXTURE
POŚREDNIE WEJŚCIA
SUT DOCTEST
FIXTURE
Indirect Input
POŚREDNIE WYJŚCIA
SUT DOCTEST
FIXTURE
Indirect Output
RODZAJE DUBLERÓW
DUMMY OBJECT
@Testpublic void shouldAddLineItem() {
Product product = new Product("Dummy Name", getUniqueNumber());Invoice invoice = new Invoice(new DummyCustomer());
invoice.addItemQuantity(product, QUANTITY);
LineItem expectedLineItem = new LineItem(invoice, product, QUANTITY);assertLineItemsEqual("", expectedLineItem, invoice.getFirstLineItem());
}
● wypełnia listę parametrów● kiedy nie można przekazać
nulla● nie używany
TEST STUB● Responder● Saboteur
TEST STUB@Testpublic void productNotFound() { mockery.checking(new Expectations() {{ allowing(catalog).findItem(BARCODE); will(throwException(new ProductNotFoundException(BARCODE))); oneOf(display).displayProductNotFoundMessage(BARCODE); }});
pointOfSale.onBarcode(BARCODE);}
@Testpublic void addAMovie() { MovieListPresenter movieListPresenter = presenterWithNoMovies(); when(movieView.getNewTitle()).thenReturn(STAR_WARS);
movieListPresenter.add();
verify(movieView).showMovies(list(movieTitled(STAR_WARS)));}
MOCK OBJECT
@Testpublic void emptyBarcode() throws Exception { mockery.checking(new Expectations() {{ oneOf(display).displayEmptyBarcodeMessage(); }});
pointOfSale.onBarcode("");}
WERYFIKACJA ZACHOWANIA
TEST SPY
STUB+MOCK
predefiniowane odpowiedzi
weryfikacja zachowania
TEST SPY
@Testpublic void addAMovie() { MovieListPresenter movieListPresenter = presenterWithNoMovies(); when(movieView.getNewTitle()).thenReturn(STAR_WARS);
movieListPresenter.add();
verify(movieView).showMovies(list(movieTitled(STAR_WARS)));}
FAKE
DZIAŁAJĄCA,ALE UPROSZCZONA
IMPLEMENTACJA
Bibliografia
● Gerard Meszaros, xUnit Test Patterns, Addison-Wesley 2007
● http://xunitpatterns.com/● http://martinfowler.com/articles/mocksArentStub
s.html
[8] http://xunitpatterns.com/Types%20Of%20Test%20Doubles.gif[9] http://www.flickr.com/photos/lincolnblues/1413187481[10,11]http://www.flickr.com/photos/21123209@N06/2460486552/ [14] http://www.flickr.com/photos/dunechaser/2630433944
DZIĘKUJĘ
Zdjęcia: